Package io.micronaut.http
Interface MutableHttpMessage<B>
-
- Type Parameters:
B
- The body type
- All Superinterfaces:
io.micronaut.core.attr.AttributeHolder
,HttpMessage<B>
,io.micronaut.core.attr.MutableAttributeHolder
- All Known Subinterfaces:
MutableHttpRequest<B>
,MutableHttpResponse<B>
- All Known Implementing Classes:
SimpleHttpRequest
public interface MutableHttpMessage<B> extends HttpMessage<B>
An interface for anHttpMessage
that is mutable allowing headers and the message body to be set.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default MutableHttpMessage<B>
basicAuth(java.lang.CharSequence username, java.lang.CharSequence password)
Set anHttpHeaders.AUTHORIZATION
header, with value: "Basic Base64(username:password)".default MutableHttpMessage<B>
bearerAuth(java.lang.CharSequence token)
Set anHttpHeaders.AUTHORIZATION
header, with value: "Bearer token".<T> MutableHttpMessage<T>
body(T body)
Sets the body.default MutableHttpMessage<B>
contentEncoding(java.lang.CharSequence encoding)
Sets the content encoding.default MutableHttpMessage<B>
contentLength(long length)
Sets the content length.default MutableHttpMessage<B>
contentType(MediaType mediaType)
Set the response content type.default MutableHttpMessage<B>
contentType(java.lang.CharSequence contentType)
Set the response content type.MutableHttpHeaders
getHeaders()
default MutableHttpMessage<B>
header(java.lang.CharSequence name, java.lang.CharSequence value)
Set a response header.default MutableHttpMessage<B>
headers(java.util.function.Consumer<MutableHttpHeaders> headers)
Mutate the headers with the given consumer.default MutableHttpMessage<B>
headers(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> namesAndValues)
Set multiple headers.-
Methods inherited from interface io.micronaut.http.HttpMessage
getAttributes, getBody, getBody, getBody, getCharacterEncoding, getContentLength, getContentType, getLocale, setAttribute
-
-
-
-
Method Detail
-
getHeaders
MutableHttpHeaders getHeaders()
- Specified by:
getHeaders
in interfaceHttpMessage<B>
- Returns:
- The
MutableHttpHeaders
object
-
body
<T> MutableHttpMessage<T> body(T body)
Sets the body.- Type Parameters:
T
- The new body type- Parameters:
body
- The body- Returns:
- This message
-
headers
default MutableHttpMessage<B> headers(java.util.function.Consumer<MutableHttpHeaders> headers)
Mutate the headers with the given consumer.- Parameters:
headers
- The headers- Returns:
- This response
-
header
default MutableHttpMessage<B> header(java.lang.CharSequence name, java.lang.CharSequence value)
Set a response header.- Parameters:
name
- The name of the headervalue
- The value of the header- Returns:
- This response
-
basicAuth
default MutableHttpMessage<B> basicAuth(java.lang.CharSequence username, java.lang.CharSequence password)
Set anHttpHeaders.AUTHORIZATION
header, with value: "Basic Base64(username:password)".- Parameters:
username
- The username part of the credentialspassword
- The password part of the credentials- Returns:
- This response
-
bearerAuth
default MutableHttpMessage<B> bearerAuth(java.lang.CharSequence token)
Set anHttpHeaders.AUTHORIZATION
header, with value: "Bearer token".- Parameters:
token
- The token- Returns:
- This response
-
headers
default MutableHttpMessage<B> headers(java.util.Map<java.lang.CharSequence,java.lang.CharSequence> namesAndValues)
Set multiple headers.- Parameters:
namesAndValues
- The names and values- Returns:
- This response
-
contentLength
default MutableHttpMessage<B> contentLength(long length)
Sets the content length.- Parameters:
length
- The length- Returns:
- This response
-
contentType
default MutableHttpMessage<B> contentType(java.lang.CharSequence contentType)
Set the response content type.- Parameters:
contentType
- The content type- Returns:
- This response
-
contentType
default MutableHttpMessage<B> contentType(MediaType mediaType)
Set the response content type.- Parameters:
mediaType
- The media type- Returns:
- This response
-
contentEncoding
default MutableHttpMessage<B> contentEncoding(java.lang.CharSequence encoding)
Sets the content encoding.- Parameters:
encoding
- The encoding to use- Returns:
- This message
-
-