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:
io.micronaut.core.attr.AttributeHolder, io.micronaut.core.attr.MutableAttributeHolder, io.micronaut.http.FullHttpRequest<T>, io.micronaut.http.HttpMessage<T>, io.micronaut.http.HttpRequest<T>, io.micronaut.http.netty.NettyHttpRequestBuilder, io.micronaut.http.PushCapableHttpRequest<T>, io.netty.util.AttributeMap

@Internal public class NettyHttpRequest<T> extends io.micronaut.http.netty.AbstractNettyHttpRequest<T> implements io.micronaut.http.HttpRequest<T>, io.micronaut.http.PushCapableHttpRequest<T>, io.micronaut.http.FullHttpRequest<T>
Delegates to the Netty HttpRequest instance.
Since:
1.0
  • Constructor Details

    • NettyHttpRequest

      public NettyHttpRequest(io.netty.handler.codec.http.HttpRequest nettyRequest, io.netty.channel.ChannelHandlerContext ctx, io.micronaut.core.convert.ConversionService environment, io.micronaut.http.server.HttpServerConfiguration serverConfiguration) throws IllegalArgumentException
      Parameters:
      nettyRequest - The HttpRequest
      ctx - The ChannelHandlerContext
      environment - The Environment
      serverConfiguration - The HttpServerConfiguration
      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, io.micronaut.core.convert.ConversionService conversionService, NettyHttpServerConfiguration serverConfiguration)
    • rootBody

      public final ByteBody rootBody()
      Get the initial body of this request. This is always a ByteBody. In most cases you should use byteBody() instead.
      Returns:
      The root body
    • byteBody

      public final ByteBody 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 called ByteBody.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

      public final HttpBody 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 "piggy-back" off other code that parses the body. For example in getBody(), 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

      public final void addRouteWaitsFor(io.micronaut.core.execution.ExecutionFlow<?> executionFlow)
    • getRouteWaitsFor

      public final io.micronaut.core.execution.ExecutionFlow<?> getRouteWaitsFor()
    • formRouteCompleter

      public final FormRouteCompleter formRouteCompleter()
    • hasFormRouteCompleter

      public final boolean hasFormRouteCompleter()
    • mutate

      public io.micronaut.http.MutableHttpRequest<T> mutate()
      Specified by:
      mutate in interface io.micronaut.http.HttpRequest<T>
    • getAttribute

      @NonNull public @NonNull Optional<Object> getAttribute(CharSequence name)
      Specified by:
      getAttribute in interface io.micronaut.core.attr.AttributeHolder
    • getHttpVersion

      public io.micronaut.http.HttpVersion getHttpVersion()
      Specified by:
      getHttpVersion in interface io.micronaut.http.HttpRequest<T>
    • 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 io.micronaut.http.cookie.Cookies getCookies()
      Specified by:
      getCookies in interface io.micronaut.http.HttpRequest<T>
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Specified by:
      getRemoteAddress in interface io.micronaut.http.HttpRequest<T>
    • getServerAddress

      public InetSocketAddress getServerAddress()
      Specified by:
      getServerAddress in interface io.micronaut.http.HttpRequest<T>
    • getServerName

      public String getServerName()
      Specified by:
      getServerName in interface io.micronaut.http.HttpRequest<T>
    • isSecure

      public boolean isSecure()
      Specified by:
      isSecure in interface io.micronaut.http.HttpRequest<T>
    • getOrigin

      public Optional<String> getOrigin()
      Specified by:
      getOrigin in interface io.micronaut.http.HttpRequest<T>
    • getHeaders

      public io.micronaut.http.HttpHeaders getHeaders()
      Specified by:
      getHeaders in interface io.micronaut.http.HttpMessage<T>
    • getAttributes

      public io.micronaut.core.convert.value.MutableConvertibleValues<Object> getAttributes()
      Specified by:
      getAttributes in interface io.micronaut.core.attr.AttributeHolder
      Specified by:
      getAttributes in interface io.micronaut.http.HttpMessage<T>
      Specified by:
      getAttributes in interface io.micronaut.core.attr.MutableAttributeHolder
    • setAttribute

      public io.micronaut.http.HttpRequest<T> setAttribute(CharSequence name, Object value)
      Specified by:
      setAttribute in interface io.micronaut.http.HttpMessage<T>
      Specified by:
      setAttribute in interface io.micronaut.http.HttpRequest<T>
      Specified by:
      setAttribute in interface io.micronaut.core.attr.MutableAttributeHolder
    • getCertificate

      public Optional<Certificate> getCertificate()
      Specified by:
      getCertificate in interface io.micronaut.http.HttpRequest<T>
    • getBody

      public Optional<T> getBody()
      Specified by:
      getBody in interface io.micronaut.http.HttpMessage<T>
    • getBody

      public <T1> Optional<T1> getBody(Class<T1> type)
      Specified by:
      getBody in interface io.micronaut.http.HttpMessage<T>
    • getBody

      public <T1> Optional<T1> getBody(io.micronaut.core.convert.ArgumentConversionContext<T1> conversionContext)
      Specified by:
      getBody in interface io.micronaut.http.HttpMessage<T>
    • release

      @Internal public void release()
      Release and cleanup resources.
    • releaseIfNecessary

      protected void releaseIfNecessary(Object value)
      Parameters:
      value - An object with a value
    • isServerPushSupported

      public boolean isServerPushSupported()
      Specified by:
      isServerPushSupported in interface io.micronaut.http.PushCapableHttpRequest<T>
    • serverPush

      public io.micronaut.http.PushCapableHttpRequest<T> serverPush(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request)
      Specified by:
      serverPush in interface io.micronaut.http.PushCapableHttpRequest<T>
    • initCharset

      protected Charset initCharset(Charset characterEncoding)
      Specified by:
      initCharset in class io.micronaut.http.netty.AbstractNettyHttpRequest<T>
    • isFormOrMultipartData

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

      @Deprecated public io.netty.handler.codec.http.HttpRequest toHttpRequest()
      Deprecated.
      Specified by:
      toHttpRequest in interface io.micronaut.http.netty.NettyHttpRequestBuilder
      Overrides:
      toHttpRequest in class io.micronaut.http.netty.AbstractNettyHttpRequest<T>
    • toHttpRequestDirect

      public Optional<io.netty.handler.codec.http.HttpRequest> toHttpRequestDirect()
      Specified by:
      toHttpRequestDirect in interface io.micronaut.http.netty.NettyHttpRequestBuilder
    • toHttpRequestWithoutBody

      public io.netty.handler.codec.http.HttpRequest toHttpRequestWithoutBody()
      Specified by:
      toHttpRequestWithoutBody in interface io.micronaut.http.netty.NettyHttpRequestBuilder
    • getContentType

      public Optional<io.micronaut.http.MediaType> getContentType()
      Specified by:
      getContentType in interface io.micronaut.http.HttpMessage<T>
      Overrides:
      getContentType in class io.micronaut.http.netty.AbstractNettyHttpRequest<T>
    • getContentLength

      public long getContentLength()
      Specified by:
      getContentLength in interface io.micronaut.http.HttpMessage<T>
    • isFull

      public boolean isFull()
      Specified by:
      isFull in interface io.micronaut.http.FullHttpRequest<T>
    • contents

      public io.micronaut.core.io.buffer.ByteBuffer<?> contents()
      Specified by:
      contents in interface io.micronaut.http.FullHttpRequest<T>
    • bufferContents

      public io.micronaut.core.execution.ExecutionFlow<io.micronaut.core.io.buffer.ByteBuffer<?>> bufferContents()
      Specified by:
      bufferContents in interface io.micronaut.http.FullHttpRequest<T>