Interface HttpRequestContext

  • All Superinterfaces:
    HttpResponder, io.netty.util.ReferenceCounted

    public interface HttpRequestContext
    extends io.netty.util.ReferenceCounted, HttpResponder
    A context that runs through each HTTP requests.
    Since:
    1.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static io.netty.util.AsciiString TEXT_PLAIN_UTF8
      "text/plain; charset=UTF-8"
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default io.netty.buffer.ByteBufAllocator alloc()
      Return the assigned ByteBufAllocator which will be used to allocate ByteBufs.
      default io.netty.buffer.ByteBuf body()
      Returns the content body of the HTTP request.
      io.netty.channel.Channel channel()
      Returns the Channel which is bound to the HttpRequestContext.
      <C extends HttpServerComponent>
      java.util.Optional<C>
      component​(java.lang.Class<? extends C> componentType)
      Returns the component with the specified componentType.
      int contentLength()
      Returns the length of the HTTP request body content.
      java.util.Optional<java.lang.CharSequence> contentType()
      Returns the type of the HTTP request body content.
      default io.netty.channel.EventLoop eventLoop()
      Return the EventLoop this Channel was registered to.
      default boolean hasProperty​(java.lang.Object key)
      Returns true if this HttpRequestContext contains a property with the specified key.
      default boolean hasProperty​(java.lang.Object key, java.lang.Object value)
      Returns true if this HttpRequestContext contains a property with the specified key and value.
      default io.netty.handler.codec.http.HttpHeaders headers()
      Returns the headers of the HTTP request.
      default boolean isKeepAlive()
      Returns if the connection is keep-alive or not.
      default io.netty.handler.codec.http.HttpMethod method()
      Returns the method of the HTTP request.
      default java.lang.String path()
      Returns the decoded path string of the HTTP request URI.
      PathVariables pathVariables()
      Returns the path variables.
      HttpResponder pathVariables​(PathVariables pathVariables)
      Set the path variables.
      default <T> java.util.Optional<T> property​(java.lang.Class<T> key)
      Returns the property value as parameterized type.
      <T> java.util.Optional<T> property​(java.lang.Object key)
      Returns the property value as parameterized type.
      <T> java.util.Optional<T> property​(java.lang.Object key, java.lang.Class<T> type)
      Returns the property value as parameterized type.
      HttpResponder property​(java.lang.Object key, java.lang.Object value)
      Set the property value with the specified key, or remove the value with specified key by input null parameter.
      java.util.stream.Stream<java.lang.String> propertyKeyNames()
      Returns a Stream contains the key name of each property in thie HttpRequestContext.
      default java.util.stream.Stream<java.lang.Object> propertyKeys()
      Deprecated.
      please use propertyKeyNames() instead
      default java.util.Optional<java.util.List<java.lang.String>> queryParameter​(java.lang.String name)
      Returns the value of the specified name belongs to the decoded key-value parameter pairs of the HTTP request URI
      default java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters()
      Returns the decoded key-value parameter pairs of the HTTP request URI.
      io.netty.handler.codec.http.QueryStringDecoder queryStringDecoder()
      Returns the QueryStringDecoder built from the HTTP request URI.
      default java.lang.String rawPath()
      Returns the raw path of the HTTP request URI.
      default java.lang.String rawQuery()
      Returns the raw query string of the HTTP request URI.
      default java.time.LocalDateTime receivedLocalTime()
      Returns the LocalDateTime when the HTTP request just received.
      long receivedNanoTime()
      Returns the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds, when the HTTP request just received.
      java.time.ZonedDateTime receivedTime()
      Returns the ZonedDateTime with the system ZoneId when the HTTP request just received.
      default java.time.ZonedDateTime receivedTime​(java.time.ZoneId zone)
      Returns the ZonedDateTime with the specified ZoneId when the HTTP request just received.
      default int refCnt()  
      default boolean release()  
      default boolean release​(int decrement)  
      java.lang.String remoteAddress()
      Returns the remote address (client IP) of this HttpRequestContext.
      io.netty.handler.codec.http.FullHttpRequest request()
      Returns the FullHttpRequest which is bound to the HttpRequestContext.
      default java.util.concurrent.CompletableFuture<HttpResult> respondBadRequestError​(java.lang.Throwable cause)
      Send HTTP response with "400 Bad Request Error" to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> respondError​(java.lang.Throwable cause)
      Respond HTTP error response to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> respondInternalServerError​(java.lang.Throwable cause)
      Send HTTP response with "500 Internal Server Error" to client and returns the HttpResult asynchronously.
      HttpRequestContext.HttpResponseFactory responseFactory()
      Returns the factory creates HttpResponses.
      default HttpRequestContext retain()  
      default HttpRequestContext retain​(int increment)  
      default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect​(java.lang.CharSequence location)
      Send HTTP response with "302 Found" to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect​(java.lang.CharSequence location, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
      Send HTTP response with "302 Found" to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> sendResponse​(io.netty.handler.codec.http.FullHttpResponse response)
      Send HTTP response to client and returns the HttpResultasynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> sendResponse​(io.netty.handler.codec.http.FullHttpResponse response, int contentLength)
      Send HTTP response to client and returns the HttpResultasynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(HttpFailureException cause)
      Respond a simple HTTP response with error message content to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status)
      Respond a simple HTTP response without content to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, int contentLength, java.lang.CharSequence contentType)
      Respond a simple HTTP response with the specified content to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status, io.netty.buffer.ByteBuf content, java.lang.CharSequence contentType)
      Respond a simple HTTP response with the specified content to client and returns the HttpResult asynchronously.
      default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status, java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
      Respond a simple HTTP response without content to client and returns the HttpResult asynchronously.
      default HttpRequestContext touch()  
      default HttpRequestContext touch​(java.lang.Object hint)  
      default io.netty.handler.codec.http.HttpHeaders trailingHeaders()
      Returns the trailing headers of the HTTP request.
      default java.lang.String uri()
      Returns the uri of the HTTP request.
      default java.util.Optional<HttpServer.User> user()
      Returns the HttpServer.User.
      default <U extends HttpServer.User>
      java.util.Optional<U>
      user​(java.lang.Class<U> type)
      Returns the HttpServer.User.
      default io.netty.handler.codec.http.HttpVersion version()
      Returns the protocol version of the HTTP request.
    • Field Detail

      • TEXT_PLAIN_UTF8

        static final io.netty.util.AsciiString TEXT_PLAIN_UTF8
        "text/plain; charset=UTF-8"
    • Method Detail

      • receivedNanoTime

        long receivedNanoTime()
        Returns the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds, when the HTTP request just received.
        Returns:
        the value of the running Java Virtual Machine'shigh-resolution time source, in nanoseconds
        See Also:
        System.nanoTime()
      • receivedTime

        java.time.ZonedDateTime receivedTime()
        Returns the ZonedDateTime with the system ZoneId when the HTTP request just received.
        Returns:
        a ZonedDateTime
      • receivedTime

        default java.time.ZonedDateTime receivedTime​(java.time.ZoneId zone)
        Returns the ZonedDateTime with the specified ZoneId when the HTTP request just received.
        Parameters:
        zone - the ZoneId
        Returns:
        a ZonedDateTime with the specified zone
      • receivedLocalTime

        default java.time.LocalDateTime receivedLocalTime()
        Returns the LocalDateTime when the HTTP request just received.
        Returns:
        a LocalDateTime
      • channel

        io.netty.channel.Channel channel()
        Returns the Channel which is bound to the HttpRequestContext.
        Returns:
        a Channel
      • eventLoop

        default io.netty.channel.EventLoop eventLoop()
        Return the EventLoop this Channel was registered to.
        Returns:
        a EventLoop
      • alloc

        default io.netty.buffer.ByteBufAllocator alloc()
        Return the assigned ByteBufAllocator which will be used to allocate ByteBufs.
        Returns:
        a ByteBufAllocator
      • remoteAddress

        java.lang.String remoteAddress()
        Returns the remote address (client IP) of this HttpRequestContext.

        All implementations should fix with the HTTP PROXY header "x-forwarded-for".

        Returns:
        the remote address
      • request

        io.netty.handler.codec.http.FullHttpRequest request()
        Returns the FullHttpRequest which is bound to the HttpRequestContext.
        Returns:
        a FullHttpRequest
      • isKeepAlive

        default boolean isKeepAlive()
        Returns if the connection is keep-alive or not.
        Returns:
        true if the connection is keep-alive, false otherwise
      • version

        default io.netty.handler.codec.http.HttpVersion version()
        Returns the protocol version of the HTTP request.
        Returns:
        the protocol version of the HTTP request
      • method

        default io.netty.handler.codec.http.HttpMethod method()
        Returns the method of the HTTP request.
        Returns:
        the method of the HTTP request
      • body

        default io.netty.buffer.ByteBuf body()
        Returns the content body of the HTTP request.
        Returns:
        the content body of the HTTP request
      • contentLength

        int contentLength()
        Returns the length of the HTTP request body content.
        Returns:
        the length of the HTTP request body content
      • headers

        default io.netty.handler.codec.http.HttpHeaders headers()
        Returns the headers of the HTTP request.
        Returns:
        the headers of the HTTP request
      • contentType

        java.util.Optional<java.lang.CharSequence> contentType()
        Returns the type of the HTTP request body content.
        Returns:
        the type of the HTTP request body content
      • trailingHeaders

        default io.netty.handler.codec.http.HttpHeaders trailingHeaders()
        Returns the trailing headers of the HTTP request.
        Returns:
        the trailing headers of the HTTP request
      • queryStringDecoder

        io.netty.handler.codec.http.QueryStringDecoder queryStringDecoder()
        Returns the QueryStringDecoder built from the HTTP request URI.
        Returns:
        a QueryStringDecoder
      • path

        default java.lang.String path()
        Returns the decoded path string of the HTTP request URI.
        Returns:
        the decoded path string
      • uri

        default java.lang.String uri()
        Returns the uri of the HTTP request.
        Returns:
        the uri string
      • rawPath

        default java.lang.String rawPath()
        Returns the raw path of the HTTP request URI.
        Returns:
        the raw path string
      • rawQuery

        default java.lang.String rawQuery()
        Returns the raw query string of the HTTP request URI.
        Returns:
        the raw query string
      • queryParameters

        default java.util.Map<java.lang.String,​java.util.List<java.lang.String>> queryParameters()
        Returns the decoded key-value parameter pairs of the HTTP request URI.
        Returns:
        the decoded key-value parameter pairs
      • queryParameter

        default java.util.Optional<java.util.List<java.lang.String>> queryParameter​(java.lang.String name)
        Returns the value of the specified name belongs to the decoded key-value parameter pairs of the HTTP request URI
        Parameters:
        name - the name of the query parameter
        Returns:
        an Optional<List<String>>
      • pathVariables

        PathVariables pathVariables()
        Returns the path variables.
        Returns:
        a PathVariables
      • pathVariables

        HttpResponder pathVariables​(PathVariables pathVariables)
        Set the path variables.
        Parameters:
        pathVariables - the path variables
        Returns:
        this HttpRequestContext
      • component

        <C extends HttpServerComponent> java.util.Optional<C> component​(java.lang.Class<? extends C> componentType)
        Returns the component with the specified componentType.
        Type Parameters:
        C - the type of the component
        Parameters:
        componentType - the type of the component
        Returns:
        an Optional<HttpServerComponent>
      • user

        default <U extends HttpServer.User> java.util.Optional<U> user​(java.lang.Class<U> type)
                                                                throws java.lang.ClassCastException
        Returns the HttpServer.User.
        Type Parameters:
        U - the real type of the user
        Parameters:
        type - the class of the real type
        Returns:
        an Optional<U extends User> may contains the user
        Throws:
        java.lang.ClassCastException - if the user is not null and is not assignable to the type U
      • property

        default <T> java.util.Optional<T> property​(java.lang.Class<T> key)
        Returns the property value as parameterized type.
        Type Parameters:
        T - the type of the property value
        Parameters:
        key - the key of the property, also the class of the type
        Returns:
        an Optional<T> may contains the property value
      • property

        <T> java.util.Optional<T> property​(java.lang.Object key)
                                    throws java.lang.ClassCastException
        Returns the property value as parameterized type.
        Type Parameters:
        T - the type of the property value
        Parameters:
        key - the key of the property
        Returns:
        an Optional<T> may contains the property value
        Throws:
        java.lang.ClassCastException - if the object is not null and is not assignable to the type T
      • property

        <T> java.util.Optional<T> property​(java.lang.Object key,
                                           java.lang.Class<T> type)
                                    throws java.lang.ClassCastException
        Returns the property value as parameterized type.
        Type Parameters:
        T - the type of the property value
        Parameters:
        key - the key of the property
        type - the class of the type
        Returns:
        an Optional<T> may contains the property value
        Throws:
        java.lang.ClassCastException - if the object is not null and is not assignable to the type T
      • property

        HttpResponder property​(java.lang.Object key,
                               java.lang.Object value)
        Set the property value with the specified key, or remove the value with specified key by input null parameter.
        Parameters:
        key - the key of the property
        value - the value of the property
        Returns:
        this HttpRequestContext
      • hasProperty

        default boolean hasProperty​(java.lang.Object key)
        Returns true if this HttpRequestContext contains a property with the specified key.
        Parameters:
        key - the key of the property
        Returns:
        true if this HttpRequestContext contains a property with the specified key
      • hasProperty

        default boolean hasProperty​(java.lang.Object key,
                                    java.lang.Object value)
        Returns true if this HttpRequestContext contains a property with the specified key and value.
        Parameters:
        key - the key of the property
        value - the value of the property
        Returns:
        true if this HttpRequestContext contains a property with the specified key and value
      • propertyKeys

        @Deprecated
        default java.util.stream.Stream<java.lang.Object> propertyKeys()
        Deprecated.
        please use propertyKeyNames() instead
        Returns a Stream contains the key of each property in this HttpRequestContext.
        Returns:
        a Stream<Object>
      • propertyKeyNames

        java.util.stream.Stream<java.lang.String> propertyKeyNames()
        Returns a Stream contains the key name of each property in thie HttpRequestContext.
        Returns:
        a Stream<String>
        Since:
        1.3
      • refCnt

        default int refCnt()
        Specified by:
        refCnt in interface io.netty.util.ReferenceCounted
      • retain

        default HttpRequestContext retain()
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
      • retain

        default HttpRequestContext retain​(int increment)
        Specified by:
        retain in interface io.netty.util.ReferenceCounted
      • touch

        default HttpRequestContext touch()
        Specified by:
        touch in interface io.netty.util.ReferenceCounted
      • touch

        default HttpRequestContext touch​(java.lang.Object hint)
        Specified by:
        touch in interface io.netty.util.ReferenceCounted
      • release

        default boolean release()
        Specified by:
        release in interface io.netty.util.ReferenceCounted
      • release

        default boolean release​(int decrement)
        Specified by:
        release in interface io.netty.util.ReferenceCounted
      • simpleRespond

        default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status)
        Description copied from interface: HttpResponder
        Respond a simple HTTP response without content to client and returns the HttpResult asynchronously.
        Specified by:
        simpleRespond in interface HttpResponder
        Parameters:
        status - the status
        Returns:
        a CompletableFuture<HttpResult>
      • simpleRespond

        default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status,
                                                                                 java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
        Description copied from interface: HttpResponder
        Respond a simple HTTP response without content to client and returns the HttpResult asynchronously.
        Specified by:
        simpleRespond in interface HttpResponder
        Parameters:
        status - the status
        addHeaders - a function to add headers
        Returns:
        a CompletableFuture<HttpResult>
      • respondError

        default java.util.concurrent.CompletableFuture<HttpResult> respondError​(java.lang.Throwable cause)
        Description copied from interface: HttpResponder
        Respond HTTP error response to client and returns the HttpResult asynchronously.
        Specified by:
        respondError in interface HttpResponder
        Parameters:
        cause - the cause
        Returns:
        a CompletableFuture<HttpResult>
      • simpleRespond

        default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(HttpFailureException cause)
        Description copied from interface: HttpResponder
        Respond a simple HTTP response with error message content to client and returns the HttpResult asynchronously.
        Specified by:
        simpleRespond in interface HttpResponder
        Parameters:
        cause - a HttpFailureException
        Returns:
        a CompletableFuture<HttpResult>
      • simpleRespond

        default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status,
                                                                                 io.netty.buffer.ByteBuf content,
                                                                                 java.lang.CharSequence contentType)
        Description copied from interface: HttpResponder
        Respond a simple HTTP response with the specified content to client and returns the HttpResult asynchronously.
        Specified by:
        simpleRespond in interface HttpResponder
        Parameters:
        status - the status
        content - the content
        contentType - the type of the content
        Returns:
        a CompletableFuture<HttpResult>
      • simpleRespond

        default java.util.concurrent.CompletableFuture<HttpResult> simpleRespond​(io.netty.handler.codec.http.HttpResponseStatus status,
                                                                                 io.netty.buffer.ByteBuf content,
                                                                                 int contentLength,
                                                                                 java.lang.CharSequence contentType)
        Description copied from interface: HttpResponder
        Respond a simple HTTP response with the specified content to client and returns the HttpResult asynchronously.
        Specified by:
        simpleRespond in interface HttpResponder
        Parameters:
        status - the status
        content - the content
        contentLength - the length of the content
        contentType - the type of the content
        Returns:
        a CompletableFuture<HttpResult>
      • respondBadRequestError

        default java.util.concurrent.CompletableFuture<HttpResult> respondBadRequestError​(java.lang.Throwable cause)
        Description copied from interface: HttpResponder
        Send HTTP response with "400 Bad Request Error" to client and returns the HttpResult asynchronously.
        Specified by:
        respondBadRequestError in interface HttpResponder
        Parameters:
        cause - the cause
        Returns:
        a CompletableFuture<HttpResult>
      • respondInternalServerError

        default java.util.concurrent.CompletableFuture<HttpResult> respondInternalServerError​(java.lang.Throwable cause)
        Description copied from interface: HttpResponder
        Send HTTP response with "500 Internal Server Error" to client and returns the HttpResult asynchronously.
        Specified by:
        respondInternalServerError in interface HttpResponder
        Parameters:
        cause - the cause
        Returns:
        a CompletableFuture<HttpResult>
      • sendResponse

        default java.util.concurrent.CompletableFuture<HttpResult> sendResponse​(io.netty.handler.codec.http.FullHttpResponse response,
                                                                                int contentLength)
        Description copied from interface: HttpResponder
        Send HTTP response to client and returns the HttpResultasynchronously.
        Specified by:
        sendResponse in interface HttpResponder
        Parameters:
        response - the FullHttpResponse
        contentLength - the length of the response body content
        Returns:
        a CompletableFuture<HttpResult>
      • sendResponse

        default java.util.concurrent.CompletableFuture<HttpResult> sendResponse​(io.netty.handler.codec.http.FullHttpResponse response)
        Description copied from interface: HttpResponder
        Send HTTP response to client and returns the HttpResultasynchronously.
        Specified by:
        sendResponse in interface HttpResponder
        Parameters:
        response - the FullHttpResponse
        Returns:
        a CompletableFuture<HttpResult>
      • sendRedirect

        default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect​(java.lang.CharSequence location)
        Description copied from interface: HttpResponder
        Send HTTP response with "302 Found" to client and returns the HttpResult asynchronously.
        Specified by:
        sendRedirect in interface HttpResponder
        Parameters:
        location - the location
        Returns:
        a CompletableFuture<HttpResult>
      • sendRedirect

        default java.util.concurrent.CompletableFuture<HttpResult> sendRedirect​(java.lang.CharSequence location,
                                                                                java.util.function.Consumer<io.netty.handler.codec.http.HttpHeaders> addHeaders)
        Description copied from interface: HttpResponder
        Send HTTP response with "302 Found" to client and returns the HttpResult asynchronously.
        Specified by:
        sendRedirect in interface HttpResponder
        Parameters:
        location - the location
        addHeaders - a function to add headers
        Returns:
        a CompletableFuture<HttpResult>