Package io.micronaut.http
Interface MutableHttpResponse<B>
-
- Type Parameters:
B- The body response type
- All Superinterfaces:
io.micronaut.core.attr.AttributeHolder,HttpMessage<B>,HttpResponse<B>,io.micronaut.core.attr.MutableAttributeHolder,MutableHttpMessage<B>
public interface MutableHttpResponse<B> extends HttpResponse<B>, MutableHttpMessage<B>
A version of theHttpResponseinterface that is mutable allowing the ability to set headers, character encoding etc.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default MutableHttpResponse<B>attribute(java.lang.CharSequence name, java.lang.Object value)Sets an attribute on the response.<T> MutableHttpResponse<T>body(T body)Sets the body.default MutableHttpResponse<B>characterEncoding(java.lang.CharSequence encoding)Sets the response encoding.default MutableHttpResponse<B>characterEncoding(java.nio.charset.Charset encoding)Sets the response encoding.default MutableHttpResponse<B>contentEncoding(java.lang.CharSequence encoding)Sets the content encoding.default MutableHttpResponse<B>contentLength(long length)Sets the content length.default MutableHttpResponse<B>contentType(MediaType mediaType)Set the response content type.default MutableHttpResponse<B>contentType(java.lang.CharSequence contentType)Set the response content type.MutableHttpResponse<B>cookie(Cookie cookie)Adds the specified cookie to the response.default MutableHttpResponse<B>cookies(java.util.Set<Cookie> cookies)Adds the specified cookies to the response.default MutableHttpResponse<B>header(java.lang.CharSequence name, java.lang.CharSequence value)Set a response header.default MutableHttpResponse<B>headers(java.util.function.Consumer<MutableHttpHeaders> headers)Mutate the headers with the given consumer.default MutableHttpResponse<B>headers(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> namesAndValues)Set multiple headers.default MutableHttpResponse<B>locale(java.util.Locale locale)Sets the locale to use and will apply the appropriateHttpHeaders.CONTENT_LANGUAGEheader to the response.default MutableHttpResponse<B>status(int status)Sets the response status.default MutableHttpResponse<B>status(int status, java.lang.CharSequence message)Sets the response status.default MutableHttpResponse<B>status(HttpStatus status)Sets the response status.MutableHttpResponse<B>status(HttpStatus status, java.lang.CharSequence message)Sets the response status.-
Methods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getCharacterEncoding, getContentLength, getContentType, getLocale
-
Methods inherited from interface io.micronaut.http.HttpResponse
body, code, getCookie, getCookies, getStatus, header, reason, setAttribute, status
-
Methods inherited from interface io.micronaut.http.MutableHttpMessage
basicAuth, bearerAuth, getHeaders
-
-
-
-
Method Detail
-
cookie
MutableHttpResponse<B> cookie(Cookie cookie)
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.- Parameters:
cookie- the Cookie to return to the client- Returns:
- This response object
-
cookies
default MutableHttpResponse<B> cookies(java.util.Set<Cookie> cookies)
Adds the specified cookies to the response.- Parameters:
cookies- the Set of Cookies to return to the client- Returns:
- This response object
-
body
<T> MutableHttpResponse<T> body(@Nullable T body)
Sets the body.- Specified by:
bodyin interfaceMutableHttpMessage<B>- Type Parameters:
T- The new body type- Parameters:
body- The body- Returns:
- This response object
-
status
MutableHttpResponse<B> status(HttpStatus status, java.lang.CharSequence message)
Sets the response status.- Parameters:
status- The statusmessage- The message- Returns:
- This response object
-
headers
default MutableHttpResponse<B> headers(java.util.function.Consumer<MutableHttpHeaders> headers)
Description copied from interface:MutableHttpMessageMutate the headers with the given consumer.- Specified by:
headersin interfaceMutableHttpMessage<B>- Parameters:
headers- The headers- Returns:
- This response
-
header
default MutableHttpResponse<B> header(java.lang.CharSequence name, java.lang.CharSequence value)
Description copied from interface:MutableHttpMessageSet a response header.- Specified by:
headerin interfaceMutableHttpMessage<B>- Parameters:
name- The name of the headervalue- The value of the header- Returns:
- This response
-
headers
default MutableHttpResponse<B> headers(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> namesAndValues)
Description copied from interface:MutableHttpMessageSet multiple headers.- Specified by:
headersin interfaceMutableHttpMessage<B>- Parameters:
namesAndValues- The names and values- Returns:
- This response
-
characterEncoding
default MutableHttpResponse<B> characterEncoding(java.lang.CharSequence encoding)
Sets the response encoding. Should be called aftercontentType(MediaType).- Parameters:
encoding- The encoding to use- Returns:
- This response object
-
characterEncoding
default MutableHttpResponse<B> characterEncoding(java.nio.charset.Charset encoding)
Sets the response encoding.- Parameters:
encoding- The encoding to use- Returns:
- The encoded reponse object
-
contentLength
default MutableHttpResponse<B> contentLength(long length)
Description copied from interface:MutableHttpMessageSets the content length.- Specified by:
contentLengthin interfaceMutableHttpMessage<B>- Parameters:
length- The length- Returns:
- This response
-
contentType
default MutableHttpResponse<B> contentType(java.lang.CharSequence contentType)
Description copied from interface:MutableHttpMessageSet the response content type.- Specified by:
contentTypein interfaceMutableHttpMessage<B>- Parameters:
contentType- The content type- Returns:
- This response
-
contentType
default MutableHttpResponse<B> contentType(MediaType mediaType)
Description copied from interface:MutableHttpMessageSet the response content type.- Specified by:
contentTypein interfaceMutableHttpMessage<B>- Parameters:
mediaType- The media type- Returns:
- This response
-
contentEncoding
default MutableHttpResponse<B> contentEncoding(java.lang.CharSequence encoding)
Description copied from interface:MutableHttpMessageSets the content encoding.- Specified by:
contentEncodingin interfaceMutableHttpMessage<B>- Parameters:
encoding- The encoding to use- Returns:
- This message
-
locale
default MutableHttpResponse<B> locale(java.util.Locale locale)
Sets the locale to use and will apply the appropriateHttpHeaders.CONTENT_LANGUAGEheader to the response.- Parameters:
locale- The locale- Returns:
- This response object
-
status
default MutableHttpResponse<B> status(int status)
Sets the response status.- Parameters:
status- The status- Returns:
- This response object
-
status
default MutableHttpResponse<B> status(int status, java.lang.CharSequence message)
Sets the response status.- Parameters:
status- The statusmessage- The message- Returns:
- This response object
-
status
default MutableHttpResponse<B> status(HttpStatus status)
Sets the response status.- Parameters:
status- The status- Returns:
- This response object
-
attribute
default MutableHttpResponse<B> attribute(java.lang.CharSequence name, java.lang.Object value)
Sets an attribute on the response.- Parameters:
name- The attribute namevalue- The attribute value- Returns:
- This response object
-
-