Class HttpConversionUtil


  • public final class HttpConversionUtil
    extends Object
    Provides utility methods and constants for the HTTP/2 to HTTP conversion
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  HttpConversionUtil.ExtensionHeaderNames
      Provides the HTTP header extensions used to carry HTTP/2 information in HTTP objects
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addHttp2ToHttpHeaders​(int streamId, Http2Headers inputHeaders, io.netty.handler.codec.http.FullHttpMessage destinationMessage, boolean addToTrailer)
      Translate and add HTTP/2 headers to HTTP/1.x headers.
      static void addHttp2ToHttpHeaders​(int streamId, Http2Headers inputHeaders, io.netty.handler.codec.http.HttpHeaders outputHeaders, io.netty.handler.codec.http.HttpVersion httpVersion, boolean isTrailer, boolean isRequest)
      Translate and add HTTP/2 headers to HTTP/1.x headers.
      static io.netty.handler.codec.http.HttpResponseStatus parseStatus​(CharSequence status)
      Apply HTTP/2 rules while translating status code to HttpResponseStatus
      static io.netty.handler.codec.http.FullHttpRequest toFullHttpRequest​(int streamId, Http2Headers http2Headers, io.netty.buffer.ByteBufAllocator alloc, boolean validateHttpHeaders)
      Create a new object to contain the request data
      static io.netty.handler.codec.http.FullHttpRequest toFullHttpRequest​(int streamId, Http2Headers http2Headers, io.netty.buffer.ByteBuf content, boolean validateHttpHeaders)
      Create a new object to contain the request data
      static io.netty.handler.codec.http.FullHttpResponse toFullHttpResponse​(int streamId, Http2Headers http2Headers, io.netty.buffer.ByteBufAllocator alloc, boolean validateHttpHeaders)
      Create a new object to contain the response data
      static io.netty.handler.codec.http.FullHttpResponse toFullHttpResponse​(int streamId, Http2Headers http2Headers, io.netty.buffer.ByteBuf content, boolean validateHttpHeaders)
      Create a new object to contain the response data
      static Http2Headers toHttp2Headers​(io.netty.handler.codec.http.HttpHeaders inHeaders, boolean validateHeaders)  
      static void toHttp2Headers​(io.netty.handler.codec.http.HttpHeaders inHeaders, Http2Headers out)  
      static Http2Headers toHttp2Headers​(io.netty.handler.codec.http.HttpMessage in, boolean validateHeaders)
      Converts the given HTTP/1.x headers into HTTP/2 headers.
      static io.netty.handler.codec.http.HttpRequest toHttpRequest​(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders)
      Create a new object to contain the request data.
      static io.netty.handler.codec.http.HttpResponse toHttpResponse​(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders)
      Create a new object to contain the response data.
    • Field Detail

      • OUT_OF_MESSAGE_SEQUENCE_METHOD

        public static final io.netty.handler.codec.http.HttpMethod OUT_OF_MESSAGE_SEQUENCE_METHOD
        This will be the method used for HttpRequest objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1
      • OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE

        public static final io.netty.handler.codec.http.HttpResponseStatus OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE
        This will be the status code used for HttpResponse objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1
    • Method Detail

      • parseStatus

        public static io.netty.handler.codec.http.HttpResponseStatus parseStatus​(CharSequence status)
                                                                          throws Http2Exception
        Apply HTTP/2 rules while translating status code to HttpResponseStatus
        Parameters:
        status - The status from an HTTP/2 frame
        Returns:
        The HTTP/1.x status
        Throws:
        Http2Exception - If there is a problem translating from HTTP/2 to HTTP/1.x
      • toFullHttpResponse

        public static io.netty.handler.codec.http.FullHttpResponse toFullHttpResponse​(int streamId,
                                                                                      Http2Headers http2Headers,
                                                                                      io.netty.buffer.ByteBufAllocator alloc,
                                                                                      boolean validateHttpHeaders)
                                                                               throws Http2Exception
        Create a new object to contain the response data
        Parameters:
        streamId - The stream associated with the response
        http2Headers - The initial set of HTTP/2 headers to create the response with
        alloc - The ByteBufAllocator to use to generate the content of the message
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new response object which represents headers/data
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
      • toFullHttpResponse

        public static io.netty.handler.codec.http.FullHttpResponse toFullHttpResponse​(int streamId,
                                                                                      Http2Headers http2Headers,
                                                                                      io.netty.buffer.ByteBuf content,
                                                                                      boolean validateHttpHeaders)
                                                                               throws Http2Exception
        Create a new object to contain the response data
        Parameters:
        streamId - The stream associated with the response
        http2Headers - The initial set of HTTP/2 headers to create the response with
        content - ByteBuf content to put in FullHttpResponse
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new response object which represents headers/data
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
      • toFullHttpRequest

        public static io.netty.handler.codec.http.FullHttpRequest toFullHttpRequest​(int streamId,
                                                                                    Http2Headers http2Headers,
                                                                                    io.netty.buffer.ByteBufAllocator alloc,
                                                                                    boolean validateHttpHeaders)
                                                                             throws Http2Exception
        Create a new object to contain the request data
        Parameters:
        streamId - The stream associated with the request
        http2Headers - The initial set of HTTP/2 headers to create the request with
        alloc - The ByteBufAllocator to use to generate the content of the message
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new request object which represents headers/data
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
      • toFullHttpRequest

        public static io.netty.handler.codec.http.FullHttpRequest toFullHttpRequest​(int streamId,
                                                                                    Http2Headers http2Headers,
                                                                                    io.netty.buffer.ByteBuf content,
                                                                                    boolean validateHttpHeaders)
                                                                             throws Http2Exception
        Create a new object to contain the request data
        Parameters:
        streamId - The stream associated with the request
        http2Headers - The initial set of HTTP/2 headers to create the request with
        content - ByteBuf content to put in FullHttpRequest
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new request object which represents headers/data
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
      • toHttpRequest

        public static io.netty.handler.codec.http.HttpRequest toHttpRequest​(int streamId,
                                                                            Http2Headers http2Headers,
                                                                            boolean validateHttpHeaders)
                                                                     throws Http2Exception
        Create a new object to contain the request data.
        Parameters:
        streamId - The stream associated with the request
        http2Headers - The initial set of HTTP/2 headers to create the request with
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new request object which represents headers for a chunked request
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
      • toHttpResponse

        public static io.netty.handler.codec.http.HttpResponse toHttpResponse​(int streamId,
                                                                              Http2Headers http2Headers,
                                                                              boolean validateHttpHeaders)
                                                                       throws Http2Exception
        Create a new object to contain the response data.
        Parameters:
        streamId - The stream associated with the response
        http2Headers - The initial set of HTTP/2 headers to create the response with
        validateHttpHeaders -
        • true to validate HTTP headers in the http-codec
        • false not to validate HTTP headers in the http-codec
        Returns:
        A new response object which represents headers for a chunked response
        Throws:
        Http2Exception - see addHttp2ToHttpHeaders(int, Http2Headers, HttpHeaders, HttpVersion, boolean, boolean)
      • addHttp2ToHttpHeaders

        public static void addHttp2ToHttpHeaders​(int streamId,
                                                 Http2Headers inputHeaders,
                                                 io.netty.handler.codec.http.FullHttpMessage destinationMessage,
                                                 boolean addToTrailer)
                                          throws Http2Exception
        Translate and add HTTP/2 headers to HTTP/1.x headers.
        Parameters:
        streamId - The stream associated with sourceHeaders.
        inputHeaders - The HTTP/2 headers to convert.
        destinationMessage - The object which will contain the resulting HTTP/1.x headers.
        addToTrailer - true to add to trailing headers. false to add to initial headers.
        Throws:
        Http2Exception - If not all HTTP/2 headers can be translated to HTTP/1.x.
        See Also:
        addHttp2ToHttpHeaders(int, Http2Headers, HttpHeaders, HttpVersion, boolean, boolean)
      • addHttp2ToHttpHeaders

        public static void addHttp2ToHttpHeaders​(int streamId,
                                                 Http2Headers inputHeaders,
                                                 io.netty.handler.codec.http.HttpHeaders outputHeaders,
                                                 io.netty.handler.codec.http.HttpVersion httpVersion,
                                                 boolean isTrailer,
                                                 boolean isRequest)
                                          throws Http2Exception
        Translate and add HTTP/2 headers to HTTP/1.x headers.
        Parameters:
        streamId - The stream associated with sourceHeaders.
        inputHeaders - The HTTP/2 headers to convert.
        outputHeaders - The object which will contain the resulting HTTP/1.x headers..
        httpVersion - What HTTP/1.x version outputHeaders should be treated as when doing the conversion.
        isTrailer - true if outputHeaders should be treated as trailing headers. false otherwise.
        isRequest - true if the outputHeaders will be used in a request message. false for response message.
        Throws:
        Http2Exception - If not all HTTP/2 headers can be translated to HTTP/1.x.
      • toHttp2Headers

        public static Http2Headers toHttp2Headers​(io.netty.handler.codec.http.HttpHeaders inHeaders,
                                                  boolean validateHeaders)
      • toHttp2Headers

        public static void toHttp2Headers​(io.netty.handler.codec.http.HttpHeaders inHeaders,
                                          Http2Headers out)