Package com.linecorp.armeria.common
Class HttpResponseBuilder
java.lang.Object
com.linecorp.armeria.common.AbstractHttpMessageBuilder
com.linecorp.armeria.common.HttpResponseBuilder
- All Implemented Interfaces:
HttpMessageSetters
Builds a new
HttpResponse
.-
Method Summary
Modifier and TypeMethodDescriptionSets 502 Bad Gateway to the status of this response.Sets 400 Bad Request to the status of this response.build()
Builds the response.Sets the content for this response.Sets the content for this response.content
(MediaType contentType, CharSequence content) Sets the content for this response.Sets the content for this response.Sets the content for this response.Sets thePublisher
for this response.Sets the content as UTF-8 for this response.Sets the content as UTF-8 for this response.Sets thePublisher
for this response.contentJson
(Object content) Sets the content for this response.Sets a cookie for this response.Sets multiple cookies for this response.created()
Sets 201 Created to the status of this response.Sets 403 Forbidden to the status of this response.header
(CharSequence name, Object value) Adds a header to this response.headers
(Iterable<? extends Map.Entry<? extends CharSequence, String>> headers) Adds multiple headers to this response.Sets 500 Internal Server Error to the status of this response.Sets 301 Moved Permanently to the status of this response.notFound()
Sets 404 Not Found to the status of this response.ok()
Sets 200 OK to the status of this response.status
(int statusCode) Sets the status for this response.status
(HttpStatus status) Sets the status for this response.trailer
(CharSequence name, Object value) Adds an HTTP trailer for this message.trailers
(Iterable<? extends Map.Entry<? extends CharSequence, String>> trailers) Adds HTTP trailers to this response.Sets 401 Unauthorized to the status of this response.Methods inherited from class com.linecorp.armeria.common.AbstractHttpMessageBuilder
publisher
-
Method Details
-
status
Sets the status for this response. -
status
Sets the status for this response. -
ok
Sets 200 OK to the status of this response. -
created
Sets 201 Created to the status of this response. -
movedPermanently
Sets 301 Moved Permanently to the status of this response. -
badRequest
Sets 400 Bad Request to the status of this response. -
unauthorized
Sets 401 Unauthorized to the status of this response. -
forbidden
Sets 403 Forbidden to the status of this response. -
notFound
Sets 404 Not Found to the status of this response. -
internalServerError
Sets 500 Internal Server Error to the status of this response. -
badGateway
Sets 502 Bad Gateway to the status of this response. -
content
Sets the content as UTF-8 for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets the content for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets the content for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets the content as UTF-8 for this response. Thecontent
is formatted byString.format(Locale, String, Object...)
with English locale.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
@FormatMethod public HttpResponseBuilder content(MediaType contentType, @FormatString String format, Object... content) Sets the content for this response. Thecontent
is formatted byString.format(Locale, String, Object...)
with English locale.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets the content for this response. Thecontent
will be wrapped usingHttpData.wrap(byte[])
, so any changes made tocontent
will be reflected in the response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets the content for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
Sets thePublisher
for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
content
public HttpResponseBuilder content(MediaType contentType, org.reactivestreams.Publisher<? extends HttpData> content) Sets thePublisher
for this response.- Specified by:
content
in interfaceHttpMessageSetters
- Overrides:
content
in classAbstractHttpMessageBuilder
-
contentJson
Sets the content for this response. Thecontent
is converted into JSON format using the defaultObjectMapper
.- Specified by:
contentJson
in interfaceHttpMessageSetters
- Overrides:
contentJson
in classAbstractHttpMessageBuilder
-
header
Adds a header to this response. For example:HttpResponse.builder() .ok() .content("Hello, Armeria") .header("Server", "foo") .build();
- Specified by:
header
in interfaceHttpMessageSetters
- Overrides:
header
in classAbstractHttpMessageBuilder
-
headers
public HttpResponseBuilder headers(Iterable<? extends Map.Entry<? extends CharSequence, String>> headers) Adds multiple headers to this response. For example:HttpResponse.builder() .ok() .content("Hello, Armeria") .headers(HttpHeaders.of("x-test-header", "foo", "Server", "baz")) .build();
- Specified by:
headers
in interfaceHttpMessageSetters
- Overrides:
headers
in classAbstractHttpMessageBuilder
- See Also:
-
trailer
Description copied from interface:HttpMessageSetters
Adds an HTTP trailer for this message.- Specified by:
trailer
in interfaceHttpMessageSetters
- Overrides:
trailer
in classAbstractHttpMessageBuilder
-
trailers
public HttpResponseBuilder trailers(Iterable<? extends Map.Entry<? extends CharSequence, String>> trailers) Adds HTTP trailers to this response.- Specified by:
trailers
in interfaceHttpMessageSetters
- Overrides:
trailers
in classAbstractHttpMessageBuilder
-
cookie
Sets a cookie for this response. For example:HttpResponse.builder() .ok() .cookie(Cookie.ofSecure("cookie", "foo")) .build();
- See Also:
-
cookies
Sets multiple cookies for this response.HttpResponse.builder() .ok() .cookies(Cookies.ofSecure(Cookie.ofSecure("cookie1", "foo"), Cookie.ofSecure("cookie2", "bar"))) .build();
- See Also:
-
build
Builds the response.
-