Class NettyHttpRequest<T>
- Type Parameters:
T- The type
- All Implemented Interfaces:
AttributeHolder,MutableAttributeHolder,FullHttpRequest<T>,HttpMessage<T>,HttpRequest<T>,NettyHttpRequestBuilder,PushCapableHttpRequest<T>,ServerHttpRequest<T>,io.netty.util.AttributeMap
HttpRequest instance.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionONLY for NettyBodyAnnotationBinder use.Fields inherited from class io.micronaut.http.server.netty.AbstractNettyHttpRequest
conversionService, httpMethod, httpMethodName, nettyRequest, unvalidatedUrlFields inherited from interface io.micronaut.http.HttpRequest
SCHEME_HTTP, SCHEME_HTTPS -
Constructor Summary
ConstructorsConstructorDescriptionNettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest, CloseableByteBody body, io.netty.channel.ChannelHandlerContext ctx, ConversionService environment, HttpServerConfiguration serverConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRouteWaitsFor(ExecutionFlow<?> executionFlow) Get the contents of this request as a buffer.byteBody()Get the bytes of the body.Directly convert this request body to aByteBody, if possible.ByteBuffer<?>contents()Get the raw body of this request.getAttribute(CharSequence name) Obtain the value of an attribute on the HTTP method.AMutableConvertibleValuesof 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.io.netty.channel.ChannelHandlerContextlongThe request or response content type.protected intio.netty.handler.codec.http.HttpRequestGet the origin header.Get the SSL session used for the connection to the client, if available.booleanprotected CharsetinitCharset(Charset characterEncoding) booleanbooleanisFull()Shortcut forcontents() != null.booleanisSecure()protected booleanbooleanCheck whether HTTP2 server push is supported by the remote client.mutate()Returns a new request object that allows mutation.voidrelease()Release and cleanup resources.serverPush(@NonNull HttpRequest<?> request) Initiate a HTTP2 server push for the given request.setAttribute(CharSequence name, Object value) Sets an attribute on the message.voidsetLegacyBody(Object legacyBody) io.netty.handler.codec.http.HttpRequestDeprecated.Optional<io.netty.handler.codec.http.HttpRequest>Directly convert this request to netty, including the body, if possible.io.netty.handler.codec.http.HttpRequestConvert this request to a netty request without the body.toString()Methods inherited from class io.micronaut.http.server.netty.AbstractNettyHttpRequest
createDecoder, getCharacterEncoding, getMethod, getMethodName, getNettyRequest, getParameters, getPath, getUri, isStream, toFullHttpRequest, toStreamHttpRequestMethods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttrMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.micronaut.core.attr.AttributeHolder
getAttributeMethods inherited from interface io.micronaut.http.HttpMessage
getBody, getBodyWriter, getCharacterEncodingMethods inherited from interface io.micronaut.http.HttpRequest
accept, getCertificate, getLocale, getMethod, getMethodName, getParameters, getPath, getUri, getUserPrincipal, getUserPrincipal, setUserPrincipal, toMutableRequestMethods inherited from interface io.micronaut.core.attr.MutableAttributeHolder
removeAttribute
-
Field Details
-
convertibleBody
ONLY for NettyBodyAnnotationBinder use.
-
-
Constructor Details
-
NettyHttpRequest
public NettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest, CloseableByteBody body, io.netty.channel.ChannelHandlerContext ctx, ConversionService environment, HttpServerConfiguration serverConfiguration) throws IllegalArgumentException - Parameters:
nettyRequest- TheHttpRequestbody- The request bodyctx- TheChannelHandlerContextenvironment- The EnvironmentserverConfiguration- TheHttpServerConfiguration- Throws:
IllegalArgumentException- When the request URI is invalid
-
-
Method Details
-
byteBody
Description copied from interface:ServerHttpRequestGet the bytes of the body. The body is owned by the request, so the caller should generally not close it or do any primary operations. The body is usually consumed by the argument binder of the controller, e.g. if it has a@Bodyargument. If you want to use the body,ByteBody.split(ByteBody.SplitBackpressureMode)it first.- Specified by:
byteBodyin interfaceServerHttpRequest<T>- Returns:
- The body bytes of this request
-
setLegacyBody
-
addRouteWaitsFor
-
getRouteWaitsFor
-
formRouteCompleter
-
hasFormRouteCompleter
public boolean hasFormRouteCompleter() -
mutate
Description copied from interface:HttpRequestReturns a new request object that allows mutation.- Specified by:
mutatein interfaceHttpRequest<T>- Returns:
- The mutable request
-
getAttribute
Description copied from interface:AttributeHolderObtain the value of an attribute on the HTTP method.- Specified by:
getAttributein interfaceAttributeHolder- Parameters:
name- The name of the attribute- Returns:
- An
Optionalvalue
-
getHttpVersion
- Specified by:
getHttpVersionin 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:
getCookiesin interfaceHttpRequest<T>- Returns:
- The
Cookiesinstance
-
getRemoteAddress
- Specified by:
getRemoteAddressin interfaceHttpRequest<T>- Returns:
- Obtain the remote address
-
getServerAddress
- Specified by:
getServerAddressin interfaceHttpRequest<T>- Returns:
- Obtain the server address
-
getServerName
- Specified by:
getServerNamein interfaceHttpRequest<T>- Returns:
- The server host name
-
isSecure
public boolean isSecure()- Specified by:
isSecurein interfaceHttpRequest<T>- Returns:
- Is the request an HTTPS request
-
getOrigin
Description copied from interface:HttpRequestGet the origin header.- Specified by:
getOriginin interfaceHttpRequest<T>- Returns:
- The origin header
- See Also:
-
getHeaders
- Specified by:
getHeadersin interfaceHttpMessage<T>- 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<T>- 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<T>- Specified by:
setAttributein interfaceHttpRequest<T>- Specified by:
setAttributein interfaceMutableAttributeHolder- Parameters:
name- The name of the attributevalue- The value of the attribute- Returns:
- This message
-
getSslSession
Description copied from interface:HttpRequestGet the SSL session used for the connection to the client, if available.- Specified by:
getSslSessionin interfaceHttpRequest<T>- Returns:
- The session
-
getBody
- Specified by:
getBodyin interfaceHttpMessage<T>- Returns:
- The request body
-
getBody
Description copied from interface:HttpMessageReturn the body as the given type.- Specified by:
getBodyin interfaceHttpMessage<T>- 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<T>- Type Parameters:
T1- 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
-
release
Release and cleanup resources. -
isServerPushSupported
public boolean isServerPushSupported()Description copied from interface:PushCapableHttpRequestCheck 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:
isServerPushSupportedin interfacePushCapableHttpRequest<T>- Returns:
trueiff server push is supported.
-
serverPush
Description copied from interface:PushCapableHttpRequestInitiate 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 therequestpassed as the parameter of this method: those headers take precedence.Security note: The
Authorizationheader 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:
serverPushin interfacePushCapableHttpRequest<T>- Parameters:
request- The request to respond to using a server push.- Returns:
- This request.
-
initCharset
- Specified by:
initCharsetin classAbstractNettyHttpRequest<T>- Parameters:
characterEncoding- The character encoding- Returns:
- The Charset
-
getMaxParams
protected int getMaxParams()- Specified by:
getMaxParamsin classAbstractNettyHttpRequest<T>- Returns:
- the maximum number of parameters.
-
isSemicolonIsNormalChar
protected boolean isSemicolonIsNormalChar()- Specified by:
isSemicolonIsNormalCharin classAbstractNettyHttpRequest<T>- Returns:
trueif yes,falseotherwise.
-
isFormOrMultipartData
- Returns:
- Return true if the request is form data.
-
toHttpRequest
Deprecated.Description copied from interface:NettyHttpRequestBuilderConverts this object to the most appropriate http request type.- Specified by:
toHttpRequestin interfaceNettyHttpRequestBuilder- Overrides:
toHttpRequestin classAbstractNettyHttpRequest<T>- Returns:
- The http request
-
toHttpRequestDirect
Description copied from interface:NettyHttpRequestBuilderDirectly 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:
toHttpRequestDirectin interfaceNettyHttpRequestBuilder- Returns:
- The request including the body
-
byteBodyDirect
Description copied from interface:NettyHttpRequestBuilderDirectly convert this request body to aByteBody, if possible. If the body of this request has been changed, this will return an empty value.- Specified by:
byteBodyDirectin interfaceNettyHttpRequestBuilder- Returns:
- The body
-
toHttpRequestWithoutBody
public io.netty.handler.codec.http.HttpRequest toHttpRequestWithoutBody()Description copied from interface:NettyHttpRequestBuilderConvert this request to a netty request without the body. The caller will handle adding the body.- Specified by:
toHttpRequestWithoutBodyin interfaceNettyHttpRequestBuilder- Returns:
- The request excluding the body
-
getContentType
Description copied from interface:HttpMessageThe request or response content type.- Specified by:
getContentTypein interfaceHttpMessage<T>- Returns:
- The content type
-
getContentLength
public long getContentLength()- Specified by:
getContentLengthin interfaceHttpMessage<T>- Returns:
- The value of the Content-Length header or -1L if none specified
-
isFull
public boolean isFull()Description copied from interface:FullHttpRequestShortcut forcontents() != null.- Specified by:
isFullin interfaceFullHttpRequest<T>- Returns:
- Is the request full.
-
contents
Description copied from interface:FullHttpRequestGet the raw body of this request. May be called multiple times. Buffer ownership is not transferred to the caller.- Specified by:
contentsin interfaceFullHttpRequest<T>- Returns:
- The body contents or null if there are none, or they are not obtainable.
-
bufferContents
Description copied from interface:FullHttpRequestGet 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:
bufferContentsin interfaceFullHttpRequest<T>- Returns:
- The request content, or
nullif buffering is not supported
-