Package io.micronaut.http.netty
Class NettyMutableHttpResponse<B>
java.lang.Object
io.micronaut.http.netty.NettyMutableHttpResponse<B>
- Type Parameters:
B- The response body
- All Implemented Interfaces:
AttributeHolder,MutableAttributeHolder,HttpMessage<B>,HttpResponse<B>,MutableHttpMessage<B>,MutableHttpResponse<B>,NettyHttpResponseBuilder
@Internal
public final class NettyMutableHttpResponse<B>
extends Object
implements MutableHttpResponse<B>, NettyHttpResponseBuilder
Delegates to Netty's
FullHttpResponse.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
ConstructorsConstructorDescriptionNettyMutableHttpResponse(ConversionService conversionService) NettyMutableHttpResponse(io.netty.handler.codec.http.FullHttpResponse nettyResponse, ConversionService conversionService) NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, ConversionService conversionService) Creates a new instance.NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, io.netty.handler.codec.http.HttpHeaders nettyHeaders, Object body, ConversionService conversionService) Creates a new instance.NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, Object body, ConversionService conversionService) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescription<T> MutableHttpResponse<T>body(T body) Sets the body.bodyWriter(MessageBodyWriter<B> messageBodyWriter) Sets the message body writer to use.intcode()contentType(MediaType mediaType) Set the response content type.Adds the specified cookie to the response.Adds the specified cookies to the response.AMutableConvertibleValuesof the attributes for this HTTP message.getBody()<T> Optional<T>getBody(ArgumentConversionContext<T> conversionContext) Return the body, will use the provided conversion context if needed.<T1> Optional<T1>Return the body as the given type.Helper method for retrieving a single Cookie on a response.Helper method for retrieving all Cookies on a response.io.netty.handler.codec.http.HttpHeadersThe netty headers.io.netty.handler.codec.http.HttpResponseStatusThe netty http response status.io.netty.handler.codec.http.HttpVersionThe netty http version.booleanisStream()reason()setAttribute(CharSequence name, Object value) Sets an attribute on the message.status(int status, CharSequence message) Sets the response status.@NonNull io.netty.handler.codec.http.FullHttpResponseConverts this object to a full http response.@NonNull io.netty.handler.codec.http.HttpResponseConverts this object to the most appropriate http response type.static @NonNull io.netty.handler.codec.http.HttpResponsetoNoBodyResponse(HttpResponse<?> response) Create a non-body netty response from the given MN response.Converts this object to a streamed http response.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute, getAttributeMethods inherited from interface io.micronaut.http.HttpMessage
getBody, getCharacterEncoding, getContentLength, getContentType, getLocaleMethods inherited from interface io.micronaut.http.HttpResponse
body, getStatus, header, statusMethods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttributeMethods inherited from interface io.micronaut.http.MutableHttpMessage
basicAuth, bearerAuthMethods inherited from interface io.micronaut.http.MutableHttpResponse
attribute, cacheControl, characterEncoding, characterEncoding, contentEncoding, contentLength, contentType, header, headers, headers, locale, status, status, status, toMutableResponse
-
Constructor Details
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.FullHttpResponse nettyResponse, ConversionService conversionService) - Parameters:
nettyResponse- TheFullHttpResponseconversionService- The conversion service
-
NettyMutableHttpResponse
- Parameters:
conversionService- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion- The http versionhttpResponseStatus- THe http response statusconversionService- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, Object body, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion- The http versionhttpResponseStatus- THe http response statusbody- The bodyconversionService- The conversion service
-
NettyMutableHttpResponse
public NettyMutableHttpResponse(io.netty.handler.codec.http.HttpVersion httpVersion, io.netty.handler.codec.http.HttpResponseStatus httpResponseStatus, io.netty.handler.codec.http.HttpHeaders nettyHeaders, Object body, ConversionService conversionService) Creates a new instance.- Parameters:
httpVersion- The http versionhttpResponseStatus- THe http response statusnettyHeaders- The http headersbody- The bodyconversionService- The conversion service
-
-
Method Details
-
toNoBodyResponse
@NonNull public static @NonNull io.netty.handler.codec.http.HttpResponse toNoBodyResponse(@NonNull HttpResponse<?> response) Create a non-body netty response from the given MN response.- Parameters:
response- The mn response- Returns:
- The netty response
-
getBodyWriter
- Specified by:
getBodyWriterin interfaceHttpMessage<B>- Returns:
- The body writer.
-
bodyWriter
Description copied from interface:MutableHttpMessageSets the message body writer to use.- Specified by:
bodyWriterin interfaceMutableHttpMessage<B>- Parameters:
messageBodyWriter- The message body writer.- Returns:
- This response
-
getNettyHttpVersion
public io.netty.handler.codec.http.HttpVersion getNettyHttpVersion()The netty http version.- Returns:
- http version
-
getNettyHttpStatus
public io.netty.handler.codec.http.HttpResponseStatus getNettyHttpStatus()The netty http response status.- Returns:
- http response status
-
getNettyHeaders
public io.netty.handler.codec.http.HttpHeaders getNettyHeaders()The netty headers.- Returns:
- netty headers
-
toString
-
getHeaders
- Specified by:
getHeadersin interfaceHttpMessage<B>- Specified by:
getHeadersin interfaceMutableHttpMessage<B>- Returns:
- The
HttpHeadersobject
-
getAttributes
Description copied from interface:HttpMessageA
MutableConvertibleValuesof the attributes for this HTTP message.Attributes are designed for internal data sharing and hence are isolated from headers and parameters which are client supplied
- Specified by:
getAttributesin interfaceAttributeHolder- Specified by:
getAttributesin interfaceHttpMessage<B>- Specified by:
getAttributesin interfaceMutableAttributeHolder- Returns:
- The attributes of the message
-
setAttribute
Description copied from interface:MutableAttributeHolderSets an attribute on the message.- Specified by:
setAttributein interfaceHttpMessage<B>- Specified by:
setAttributein interfaceHttpResponse<B>- Specified by:
setAttributein interfaceMutableAttributeHolder- Parameters:
name- The name of the attributevalue- The value of the attribute- Returns:
- This message
-
code
public int code()- Specified by:
codein interfaceHttpResponse<B>- Returns:
- The response status code
-
reason
- Specified by:
reasonin interfaceHttpResponse<B>- Returns:
- The HTTP status reason phrase
-
cookie
Description copied from interface:MutableHttpResponseAdds the specified cookie to the response. This method can be called multiple times to set more than one cookie.- Specified by:
cookiein interfaceMutableHttpResponse<B>- Parameters:
cookie- the Cookie to return to the client- Returns:
- This response object
-
cookies
Description copied from interface:MutableHttpResponseAdds the specified cookies to the response.- Specified by:
cookiesin interfaceMutableHttpResponse<B>- Parameters:
cookies- the Set of Cookies to return to the client- Returns:
- This response object
-
getCookies
Description copied from interface:HttpResponseHelper method for retrieving all Cookies on a response.- Specified by:
getCookiesin interfaceHttpResponse<B>- Returns:
- The cookies on the response
-
getCookie
Description copied from interface:HttpResponseHelper method for retrieving a single Cookie on a response.- Specified by:
getCookiein interfaceHttpResponse<B>- Parameters:
name- The name of the Cookie- Returns:
- The Cookie
-
getBody
- Specified by:
getBodyin interfaceHttpMessage<B>- Returns:
- The request body
-
getBody
Description copied from interface:HttpMessageReturn the body as the given type.- Specified by:
getBodyin interfaceHttpMessage<B>- Type Parameters:
T1- The generic type- Parameters:
type- The type of the body- Returns:
- An
Optionalof the type orOptional.empty()if the body cannot be returned as the given type
-
getBody
Description copied from interface:HttpMessageReturn the body, will use the provided conversion context if needed.- Specified by:
getBodyin interfaceHttpMessage<B>- Type Parameters:
T- The generic type- Parameters:
conversionContext- The body conversion context- Returns:
- An
Optionalof the type orOptional.empty()if the body cannot be returned as the given type
-
status
Description copied from interface:MutableHttpResponseSets the response status.- Specified by:
statusin interfaceMutableHttpResponse<B>- Parameters:
status- The statusmessage- The message- Returns:
- This response object
-
body
Description copied from interface:MutableHttpResponseSets the body.- Specified by:
bodyin interfaceMutableHttpMessage<B>- Specified by:
bodyin interfaceMutableHttpResponse<B>- Type Parameters:
T- The new body type- Parameters:
body- The body- Returns:
- This response object
-
contentType
Description copied from interface:MutableHttpMessageSet the response content type.- Specified by:
contentTypein interfaceMutableHttpMessage<B>- Specified by:
contentTypein interfaceMutableHttpResponse<B>- Parameters:
mediaType- The media type- Returns:
- This response
-
toFullHttpResponse
Description copied from interface:NettyHttpResponseBuilderConverts this object to a full http response.- Specified by:
toFullHttpResponsein interfaceNettyHttpResponseBuilder- Returns:
- a full http response
-
toStreamHttpResponse
Description copied from interface:NettyHttpResponseBuilderConverts this object to a streamed http response.- Specified by:
toStreamHttpResponsein interfaceNettyHttpResponseBuilder- Returns:
- The streamed response
-
toHttpResponse
Description copied from interface:NettyHttpResponseBuilderConverts this object to the most appropriate http response type.- Specified by:
toHttpResponsein interfaceNettyHttpResponseBuilder- Returns:
- The http response
-
isStream
public boolean isStream()- Specified by:
isStreamin interfaceNettyHttpResponseBuilder- Returns:
- Is the response a stream.
-