public interface HttpResponse
Modifier and Type | Method and Description |
---|---|
void |
appendHeader(String header,
String value)
Includes the given header name with the given value in the response.
|
Optional<String> |
getContentType()
Returns the
Content-Type that was previously set by setContentType(java.lang.String) , or by
appendHeader(java.lang.String, java.lang.String) with a header name of Content-Type . |
Map<String,List<String>> |
getHeaders()
Returns the headers that have been defined for the response so far.
|
OutputStream |
getOutputStream()
Returns an
OutputStream that can be used to write the body of the response. |
BufferedWriter |
getWriter()
Returns a
BufferedWriter that can be used to write the text body of the response. |
void |
setContentType(String contentType)
Sets the value to use for the
Content-Type header in the response. |
void |
setStatusCode(int code)
Sets the numeric HTTP
status
code to use in the response.
|
void |
setStatusCode(int code,
String message)
Sets the numeric HTTP
status
code and reason message to use in the response.
|
void setStatusCode(int code)
void setStatusCode(int code, String message)
setStatusCode(400, "Something went wrong")
.void setContentType(String contentType)
Content-Type
header in the response. This may include
a character encoding, for example setContentType("text/plain; charset=utf-8")
.Optional<String> getContentType()
Content-Type
that was previously set by setContentType(java.lang.String)
, or by
appendHeader(java.lang.String, java.lang.String)
with a header name of Content-Type
. If no Content-Type
has been set, returns Optional.empty()
.void appendHeader(String header, String value)
Map<String,List<String>> getHeaders()
appendHeader(java.lang.String, java.lang.String)
or setContentType(java.lang.String)
, and may
contain additional headers such as Date
.OutputStream getOutputStream() throws IOException
OutputStream
that can be used to write the body of the response.
This method is typically used to write binary data. If the body is text, the
getWriter()
method is more appropriate.IOException
- if a valid OutputStream
cannot be returned for some reason.IllegalStateException
- if getWriter()
has already been called on this instance.BufferedWriter getWriter() throws IOException
BufferedWriter
that can be used to write the text body of the response.
If the written text will not be US-ASCII, you should specify a character encoding by calling
setContentType("text/foo; charset=bar")
or
appendHeader("Content-Type", "text/foo; charset=bar")
before calling this method.IOException
- if a valid BufferedWriter
cannot be returned for some reason.IllegalStateException
- if getOutputStream()
has already been called on this
instance.Copyright © 2019. All rights reserved.