Class NettyHttpRequest<T>

java.lang.Object
io.netty.util.DefaultAttributeMap
io.micronaut.http.netty.AbstractNettyHttpRequest<T>
io.micronaut.http.server.netty.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

@Internal public final class NettyHttpRequest<T> extends AbstractNettyHttpRequest<T> implements HttpRequest<T>, PushCapableHttpRequest<T>, FullHttpRequest<T>, ServerHttpRequest<T>
Delegates to the Netty HttpRequest instance.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

  • Constructor Details

  • Method Details

    • byteBody

      public ByteBody byteBody()
      Description copied from interface: ServerHttpRequest
      Get 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 @Body argument. If you want to use the body, ByteBody.split(ByteBody.SplitBackpressureMode) it first.
      Specified by:
      byteBody in interface ServerHttpRequest<T>
      Returns:
      The body bytes of this request
    • setLegacyBody

      public void setLegacyBody(Object legacyBody)
    • addRouteWaitsFor

      public void addRouteWaitsFor(ExecutionFlow<?> executionFlow)
    • getRouteWaitsFor

      public ExecutionFlow<?> getRouteWaitsFor()
    • formRouteCompleter

      public FormRouteCompleter formRouteCompleter()
    • hasFormRouteCompleter

      public boolean hasFormRouteCompleter()
    • mutate

      public MutableHttpRequest<T> mutate()
      Description copied from interface: HttpRequest
      Returns a new request object that allows mutation.
      Specified by:
      mutate in interface HttpRequest<T>
      Returns:
      The mutable request
    • getAttribute

      @NonNull public @NonNull Optional<Object> getAttribute(CharSequence name)
      Description copied from interface: AttributeHolder
      Obtain the value of an attribute on the HTTP method.
      Specified by:
      getAttribute in interface AttributeHolder
      Parameters:
      name - The name of the attribute
      Returns:
      An Optional value
    • getHttpVersion

      public HttpVersion getHttpVersion()
      Specified by:
      getHttpVersion in interface HttpRequest<T>
      Returns:
      The http version of the request.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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

      public Cookies getCookies()
      Specified by:
      getCookies in interface HttpRequest<T>
      Returns:
      The Cookies instance
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Specified by:
      getRemoteAddress in interface HttpRequest<T>
      Returns:
      Obtain the remote address
    • getServerAddress

      public InetSocketAddress getServerAddress()
      Specified by:
      getServerAddress in interface HttpRequest<T>
      Returns:
      Obtain the server address
    • getServerName

      public String getServerName()
      Specified by:
      getServerName in interface HttpRequest<T>
      Returns:
      The server host name
    • isSecure

      public boolean isSecure()
      Specified by:
      isSecure in interface HttpRequest<T>
      Returns:
      Is the request an HTTPS request
    • getOrigin

      public Optional<String> getOrigin()
      Description copied from interface: HttpRequest
      Get the origin header.
      Specified by:
      getOrigin in interface HttpRequest<T>
      Returns:
      The origin header
      See Also:
    • getHeaders

      public HttpHeaders getHeaders()
      Specified by:
      getHeaders in interface HttpMessage<T>
      Returns:
      The HttpHeaders object
    • getAttributes

      public MutableConvertibleValues<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 interface AttributeHolder
      Specified by:
      getAttributes in interface HttpMessage<T>
      Specified by:
      getAttributes in interface MutableAttributeHolder
      Returns:
      The attributes of the message
    • setAttribute

      public HttpRequest<T> setAttribute(CharSequence name, Object value)
      Description copied from interface: MutableAttributeHolder
      Sets an attribute on the message.
      Specified by:
      setAttribute in interface HttpMessage<T>
      Specified by:
      setAttribute in interface HttpRequest<T>
      Specified by:
      setAttribute in interface MutableAttributeHolder
      Parameters:
      name - The name of the attribute
      value - The value of the attribute
      Returns:
      This message
    • getSslSession

      public Optional<SSLSession> getSslSession()
      Description copied from interface: HttpRequest
      Get the SSL session used for the connection to the client, if available.
      Specified by:
      getSslSession in interface HttpRequest<T>
      Returns:
      The session
    • getBody

      public Optional<T> getBody()
      Specified by:
      getBody in interface HttpMessage<T>
      Returns:
      The request body
    • getBody

      public <T1> Optional<T1> getBody(Class<T1> type)
      Description copied from interface: HttpMessage
      Return the body as the given type.
      Specified by:
      getBody in interface HttpMessage<T>
      Type Parameters:
      T1 - The generic type
      Parameters:
      type - The type of the body
      Returns:
      An Optional of the type or Optional.empty() if the body cannot be returned as the given type
    • getBody

      public <T1> Optional<T1> getBody(ArgumentConversionContext<T1> conversionContext)
      Description copied from interface: HttpMessage
      Return the body, will use the provided conversion context if needed.
      Specified by:
      getBody in interface HttpMessage<T>
      Type Parameters:
      T1 - The generic type
      Parameters:
      conversionContext - The body conversion context
      Returns:
      An Optional of the type or Optional.empty() if the body cannot be returned as the given type
    • release

      @Internal public void release()
      Release and cleanup resources.
    • 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 return true.
      Specified by:
      isServerPushSupported in interface PushCapableHttpRequest<T>
      Returns:
      true iff server push is supported.
    • serverPush

      public PushCapableHttpRequest<T> serverPush(@NonNull @NonNull HttpRequest<?> request)
      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 the request 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 HTTP2 PUSH_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 interface PushCapableHttpRequest<T>
      Parameters:
      request - The request to respond to using a server push.
      Returns:
      This request.
    • initCharset

      protected Charset initCharset(Charset characterEncoding)
      Specified by:
      initCharset in class AbstractNettyHttpRequest<T>
      Parameters:
      characterEncoding - The character encoding
      Returns:
      The Charset
    • isFormOrMultipartData

      @Internal public boolean isFormOrMultipartData()
      Returns:
      Return true if the request is form data.
    • toHttpRequest

      @Deprecated public io.netty.handler.codec.http.HttpRequest toHttpRequest()
      Deprecated.
      Description copied from interface: NettyHttpRequestBuilder
      Converts this object to the most appropriate http request type.
      Specified by:
      toHttpRequest in interface NettyHttpRequestBuilder
      Overrides:
      toHttpRequest in class AbstractNettyHttpRequest<T>
      Returns:
      The http request
    • toHttpRequestDirect

      public Optional<io.netty.handler.codec.http.HttpRequest> 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 interface NettyHttpRequestBuilder
      Returns:
      The request including the body
    • byteBodyDirect

      public ByteBody byteBodyDirect()
      Description copied from interface: NettyHttpRequestBuilder
      Directly convert this request body to a ByteBody, if possible. If the body of this request has been changed, this will return an empty value.
      Specified by:
      byteBodyDirect in interface NettyHttpRequestBuilder
      Returns:
      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 interface NettyHttpRequestBuilder
      Returns:
      The request excluding the body
    • getContentType

      public Optional<MediaType> getContentType()
      Description copied from interface: HttpMessage
      The request or response content type.
      Specified by:
      getContentType in interface HttpMessage<T>
      Returns:
      The content type
    • getContentLength

      public long getContentLength()
      Specified by:
      getContentLength in interface HttpMessage<T>
      Returns:
      The value of the Content-Length header or -1L if none specified
    • isFull

      public boolean isFull()
      Description copied from interface: FullHttpRequest
      Shortcut for contents() != null.
      Specified by:
      isFull in interface FullHttpRequest<T>
      Returns:
      Is the request full.
    • contents

      public ByteBuffer<?> 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 interface FullHttpRequest<T>
      Returns:
      The body contents or null if there are none, or they are not obtainable.
    • bufferContents

      public ExecutionFlow<ByteBuffer<?>> 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 return null. Once the returned flow completes, FullHttpRequest.contents() must return the same value.
      Specified by:
      bufferContents in interface FullHttpRequest<T>
      Returns:
      The request content, or null if buffering is not supported