Class NettyHttpRequest<T>
- Type Parameters:
T
- The type
- All Implemented Interfaces:
AttributeHolder
,MutableAttributeHolder
,FullHttpRequest<T>
,HttpMessage<T>
,HttpRequest<T>
,NettyHttpRequestBuilder
,PushCapableHttpRequest<T>
,io.netty.util.AttributeMap
HttpRequest
instance.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Fields inherited from class io.micronaut.http.netty.AbstractNettyHttpRequest
conversionService, httpMethod, httpMethodName, nettyRequest, uri
Fields inherited from interface io.micronaut.http.HttpRequest
SCHEME_HTTP, SCHEME_HTTPS
-
Constructor Summary
ConstructorDescriptionNettyHttpRequest
(io.netty.handler.codec.http.HttpRequest nettyRequest, io.netty.channel.ChannelHandlerContext ctx, ConversionService environment, HttpServerConfiguration serverConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addRouteWaitsFor
(ExecutionFlow<?> executionFlow) Get the contents of this request as a buffer.final ByteBody
byteBody()
Get the last byte body of this request, be it claimed or unclaimed.ByteBuffer<?>
contents()
Get the raw body of this request.static NettyHttpRequest<?>
createSafe
(io.netty.handler.codec.http.HttpRequest request, io.netty.channel.ChannelHandlerContext ctx, ConversionService conversionService, NettyHttpServerConfiguration serverConfiguration) final FormRouteCompleter
getAttribute
(CharSequence name) Obtain the value of an attribute on the HTTP method.AMutableConvertibleValues
of the attributes for this HTTP message.getBody()
<T1> Optional<T1>
getBody
(ArgumentConversionContext<T1> conversionContext) Return the body, will use the provided conversion context if needed.<T1> Optional<T1>
Return the body as the given type.Retrieves the Certificate used for mutual authentication.io.netty.channel.ChannelHandlerContext
long
The request or response content type.io.netty.handler.codec.http.HttpRequest
Get the origin header.final ExecutionFlow<?>
final boolean
protected Charset
initCharset
(Charset characterEncoding) final boolean
boolean
isFull()
Shortcut forcontents() != null
.boolean
isSecure()
boolean
Check whether HTTP2 server push is supported by the remote client.final HttpBody
lastBody()
Get the last body of this request, of any type.mutate()
Returns a new request object that allows mutation.void
release()
Release and cleanup resources.protected void
releaseIfNecessary
(Object value) final ByteBody
rootBody()
Get the initial body of this request.serverPush
(@NonNull HttpRequest<?> request) Initiate a HTTP2 server push for the given request.setAttribute
(CharSequence name, Object value) Sets an attribute on the message.io.netty.handler.codec.http.HttpRequest
Deprecated.Optional<io.netty.handler.codec.http.HttpRequest>
Directly convert this request to netty, including the body, if possible.io.netty.handler.codec.http.HttpRequest
Convert this request to a netty request without the body.toString()
Methods inherited from class io.micronaut.http.netty.AbstractNettyHttpRequest
accept, createDecoder, getCharacterEncoding, getLocale, getMethod, getMethodName, getNettyRequest, getParameters, getPath, getUri, isStream, toFullHttpRequest, toStreamHttpRequest
Methods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttribute
Methods inherited from interface io.micronaut.http.HttpMessage
getBody, getBodyWriter, getCharacterEncoding
Methods inherited from interface io.micronaut.http.HttpRequest
accept, getLocale, getMethod, getMethodName, getParameters, getPath, getUri, getUserPrincipal, getUserPrincipal
Methods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
-
Constructor Details
-
NettyHttpRequest
public NettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest, io.netty.channel.ChannelHandlerContext ctx, ConversionService environment, HttpServerConfiguration serverConfiguration) throws IllegalArgumentException - Parameters:
nettyRequest
- TheHttpRequest
ctx
- TheChannelHandlerContext
environment
- The EnvironmentserverConfiguration
- TheHttpServerConfiguration
- Throws:
IllegalArgumentException
- When the request URI is invalid
-
-
Method Details
-
createSafe
public static NettyHttpRequest<?> createSafe(io.netty.handler.codec.http.HttpRequest request, io.netty.channel.ChannelHandlerContext ctx, ConversionService conversionService, NettyHttpServerConfiguration serverConfiguration) -
rootBody
Get the initial body of this request. This is always aByteBody
. In most cases you should usebyteBody()
instead.- Returns:
- The root body
-
byteBody
Get the last byte body of this request, be it claimed or unclaimed. Basically, there are two options: For buffered requests (rootBody is immediate), this is just the root body. For streaming requests (rootBody is streaming), this can be that root body, or if someone calledByteBody.buffer(io.netty.buffer.ByteBufAllocator)
(and the buffering has completed), it can be the buffered immediate body.
The returned byte body may have been claimed already.- Returns:
- The byte body of this request
-
lastBody
Get the last body of this request, of any type. This is a weird method to use, avoid it. It's sometimes necessary to "piggyback" off other code that parses the body. For example ingetBody()
, we want to return whatever we can, even if the body has already been claimed for a@Body
parameter or form parsing or something. So we take the last step in the parse chain and do our best with it.- Returns:
- The last body of this request
-
addRouteWaitsFor
-
getRouteWaitsFor
-
formRouteCompleter
-
hasFormRouteCompleter
public final boolean hasFormRouteCompleter() -
mutate
Description copied from interface:HttpRequest
Returns a new request object that allows mutation.- Specified by:
mutate
in interfaceHttpRequest<T>
- Returns:
- The mutable request
-
getAttribute
Description copied from interface:AttributeHolder
Obtain the value of an attribute on the HTTP method.- Specified by:
getAttribute
in interfaceAttributeHolder
- Parameters:
name
- The name of the attribute- Returns:
- An
Optional
value
-
getHttpVersion
- Specified by:
getHttpVersion
in interfaceHttpRequest<T>
- Returns:
- The http version of the request.
-
toString
-
getNativeRequest
public io.netty.handler.codec.http.HttpRequest getNativeRequest()- Returns:
- Obtain a reference to the native Netty HTTP request
-
getChannelHandlerContext
public io.netty.channel.ChannelHandlerContext getChannelHandlerContext()- Returns:
- The
ChannelHandlerContext
-
getCookies
- Specified by:
getCookies
in interfaceHttpRequest<T>
- Returns:
- The
Cookies
instance
-
getRemoteAddress
- Specified by:
getRemoteAddress
in interfaceHttpRequest<T>
- Returns:
- Obtain the remote address
-
getServerAddress
- Specified by:
getServerAddress
in interfaceHttpRequest<T>
- Returns:
- Obtain the server address
-
getServerName
- Specified by:
getServerName
in interfaceHttpRequest<T>
- Returns:
- The server host name
-
isSecure
public boolean isSecure()- Specified by:
isSecure
in interfaceHttpRequest<T>
- Returns:
- Is the request an HTTPS request
-
getOrigin
Description copied from interface:HttpRequest
Get the origin header.- Specified by:
getOrigin
in interfaceHttpRequest<T>
- Returns:
- The origin header
- See Also:
-
getHeaders
- Specified by:
getHeaders
in interfaceHttpMessage<T>
- Returns:
- The
HttpHeaders
object
-
getAttributes
Description copied from interface:HttpMessage
A
MutableConvertibleValues
of 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:
getAttributes
in interfaceAttributeHolder
- Specified by:
getAttributes
in interfaceHttpMessage<T>
- Specified by:
getAttributes
in interfaceMutableAttributeHolder
- Returns:
- The attributes of the message
-
setAttribute
Description copied from interface:MutableAttributeHolder
Sets an attribute on the message.- Specified by:
setAttribute
in interfaceHttpMessage<T>
- Specified by:
setAttribute
in interfaceHttpRequest<T>
- Specified by:
setAttribute
in interfaceMutableAttributeHolder
- Parameters:
name
- The name of the attributevalue
- The value of the attribute- Returns:
- This message
-
getCertificate
Description copied from interface:HttpRequest
Retrieves the Certificate used for mutual authentication.- Specified by:
getCertificate
in interfaceHttpRequest<T>
- Returns:
- A certificate used for authentication, if applicable.
-
getBody
- Specified by:
getBody
in interfaceHttpMessage<T>
- Returns:
- The request body
-
getBody
Description copied from interface:HttpMessage
Return the body as the given type.- Specified by:
getBody
in interfaceHttpMessage<T>
- Type Parameters:
T1
- The generic type- Parameters:
type
- The type of the body- Returns:
- An
Optional
of the type orOptional.empty()
if the body cannot be returned as the given type
-
getBody
Description copied from interface:HttpMessage
Return the body, will use the provided conversion context if needed.- Specified by:
getBody
in interfaceHttpMessage<T>
- Type Parameters:
T1
- The generic type- Parameters:
conversionContext
- The body conversion context- Returns:
- An
Optional
of the type orOptional.empty()
if the body cannot be returned as the given type
-
release
Release and cleanup resources. -
releaseIfNecessary
- Parameters:
value
- An object with a value
-
isServerPushSupported
public boolean isServerPushSupported()Description copied from interface:PushCapableHttpRequest
Check whether HTTP2 server push is supported by the remote client. Only HTTP2 clients that indicate support through HTTP2 settings have this method returntrue
.- Specified by:
isServerPushSupported
in interfacePushCapableHttpRequest<T>
- Returns:
true
iff server push is supported.
-
serverPush
Description copied from interface:PushCapableHttpRequest
Initiate a HTTP2 server push for the given request. The information from the given request (i.e. path, headers) will be passed on to the client immediately so that it does not send the request itself. Then, the given request will be handled as if it was initiated by the client, and the response will be passed back to the client.
This method mostly follows the semantics of JavaEE
javax.servlet.http.PushBuilder
. This means most of the headers of this request are copied into the push request, and the referer is set. To override this behavior, add a corresponding header to therequest
passed as the parameter of this method: those headers take precedence.Security note: The
Authorization
header and other headers not excluded by the above paragraph will be copied and sent to the client as part of a HTTP2PUSH_PROMISE
. Normally, this is fine, because the client sent those headers in the first place. But if there is an intermediate proxy that added a header, this header may then leak to the client.- Specified by:
serverPush
in interfacePushCapableHttpRequest<T>
- Parameters:
request
- The request to respond to using a server push.- Returns:
- This request.
-
initCharset
- Specified by:
initCharset
in classAbstractNettyHttpRequest<T>
- Parameters:
characterEncoding
- The charactger encoding- Returns:
- The Charset
-
isFormOrMultipartData
- Returns:
- Return true if the request is form data.
-
toHttpRequest
Deprecated.Description copied from interface:NettyHttpRequestBuilder
Converts this object to the most appropriate http request type.- Specified by:
toHttpRequest
in interfaceNettyHttpRequestBuilder
- Overrides:
toHttpRequest
in classAbstractNettyHttpRequest<T>
- Returns:
- The http request
-
toHttpRequestDirect
Description copied from interface:NettyHttpRequestBuilder
Directly convert this request to netty, including the body, if possible. If the body of this request has been changed, this will return an empty value.- Specified by:
toHttpRequestDirect
in interfaceNettyHttpRequestBuilder
- Returns:
- The request including the body
-
toHttpRequestWithoutBody
public io.netty.handler.codec.http.HttpRequest toHttpRequestWithoutBody()Description copied from interface:NettyHttpRequestBuilder
Convert this request to a netty request without the body. The caller will handle adding the body.- Specified by:
toHttpRequestWithoutBody
in interfaceNettyHttpRequestBuilder
- Returns:
- The request excluding the body
-
getContentType
Description copied from interface:HttpMessage
The request or response content type.- Specified by:
getContentType
in interfaceHttpMessage<T>
- Overrides:
getContentType
in classAbstractNettyHttpRequest<T>
- Returns:
- The content type
-
getContentLength
public long getContentLength()- Specified by:
getContentLength
in interfaceHttpMessage<T>
- Returns:
- The value of the Content-Length header or -1L if none specified
-
isFull
public boolean isFull()Description copied from interface:FullHttpRequest
Shortcut forcontents() != null
.- Specified by:
isFull
in interfaceFullHttpRequest<T>
- Returns:
- Is the request full.
-
contents
Description copied from interface:FullHttpRequest
Get the raw body of this request. May be called multiple times. Buffer ownership is not transferred to the caller.- Specified by:
contents
in interfaceFullHttpRequest<T>
- Returns:
- The body contents or null if there are none, or they are not obtainable.
-
bufferContents
Description copied from interface:FullHttpRequest
Get the contents of this request as a buffer. If this is a streaming request, the returned flow may be delayed. If buffering is not supported for this request, this may returnnull
. Once the returned flow completes,FullHttpRequest.contents()
must return the same value.- Specified by:
bufferContents
in interfaceFullHttpRequest<T>
- Returns:
- The request content, or
null
if buffering is not supported
-