Package io.netty.handler.codec.http2
Class HttpConversionUtil
java.lang.Object
io.netty.handler.codec.http2.HttpConversionUtil
Provides utility methods and constants for the HTTP/2 to HTTP conversion
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Provides the HTTP header extensions used to carry HTTP/2 information in HTTP objectsprivate static final class
Utility which translates HTTP/2 headers to HTTP/1 headers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final AsciiString
[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be/
.private static final CharSequenceMap
<AsciiString> The set of headers that should not be directly copied when converting headers from HTTP to HTTP/2.static final HttpMethod
This will be the method used forHttpRequest
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1static final String
This will be the path used forHttpRequest
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1static final HttpResponseStatus
This will be the status code used forHttpResponse
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addHttp2ToHttpHeaders
(int streamId, Http2Headers inputHeaders, FullHttpMessage destinationMessage, boolean addToTrailer) Translate and add HTTP/2 headers to HTTP/1.x headers.static void
addHttp2ToHttpHeaders
(int streamId, Http2Headers inputHeaders, HttpHeaders outputHeaders, HttpVersion httpVersion, boolean isTrailer, boolean isRequest) Translate and add HTTP/2 headers to HTTP/1.x headers.private static String
extractPath
(CharSequence method, Http2Headers headers) static HttpResponseStatus
parseStatus
(CharSequence status) Apply HTTP/2 rules while translating status code toHttpResponseStatus
(package private) static void
setHttp2Authority
(String authority, Http2Headers out) private static void
setHttp2Scheme
(HttpHeaders in, Http2Headers out) private static void
setHttp2Scheme
(HttpHeaders in, URI uri, Http2Headers out) private static void
splitValidCookieHeader
(Http2Headers out, CharSequence valueCs) static FullHttpRequest
toFullHttpRequest
(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders) Create a new object to contain the request datastatic FullHttpRequest
toFullHttpRequest
(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders) Create a new object to contain the request datastatic FullHttpResponse
toFullHttpResponse
(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders) Create a new object to contain the response datastatic FullHttpResponse
toFullHttpResponse
(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders) Create a new object to contain the response datastatic Http2Headers
toHttp2Headers
(HttpHeaders inHeaders, boolean validateHeaders) static void
toHttp2Headers
(HttpHeaders inHeaders, Http2Headers out) static Http2Headers
toHttp2Headers
(HttpMessage in, boolean validateHeaders) Converts the given HTTP/1.x headers into HTTP/2 headers.private static void
toHttp2HeadersFilterTE
(Map.Entry<CharSequence, CharSequence> entry, Http2Headers out) Filter theHttpHeaderNames.TE
header according to the special rules in the HTTP/2 RFC.private static AsciiString
toHttp2Path
(URI uri) Generate an HTTP/2 {code :path} from a URI in accordance with rfc7230, 5.3.static HttpRequest
toHttpRequest
(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders) Create a new object to contain the request data.static HttpResponse
toHttpResponse
(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders) Create a new object to contain the response data.private static CharSequenceMap
<AsciiString> toLowercaseMap
(Iterator<? extends CharSequence> valuesIter, int arraySizeHint)
-
Field Details
-
HTTP_TO_HTTP2_HEADER_BLACKLIST
The set of headers that should not be directly copied when converting headers from HTTP to HTTP/2. -
OUT_OF_MESSAGE_SEQUENCE_METHOD
This will be the method used forHttpRequest
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1 -
OUT_OF_MESSAGE_SEQUENCE_PATH
This will be the path used forHttpRequest
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1- See Also:
-
OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE
This will be the status code used forHttpResponse
objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1 -
EMPTY_REQUEST_PATH
[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be/
.
-
-
Constructor Details
-
HttpConversionUtil
private HttpConversionUtil()
-
-
Method Details
-
parseStatus
Apply HTTP/2 rules while translating status code toHttpResponseStatus
- 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 FullHttpResponse toFullHttpResponse(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders) throws Http2Exception Create a new object to contain the response data- Parameters:
streamId
- The stream associated with the responsehttp2Headers
- The initial set of HTTP/2 headers to create the response withalloc
- TheByteBufAllocator
to use to generate the content of the messagevalidateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new response object which represents headers/data
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
-
toFullHttpResponse
public static FullHttpResponse toFullHttpResponse(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders) throws Http2Exception Create a new object to contain the response data- Parameters:
streamId
- The stream associated with the responsehttp2Headers
- The initial set of HTTP/2 headers to create the response withcontent
-ByteBuf
content to put inFullHttpResponse
validateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new response object which represents headers/data
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
-
toFullHttpRequest
public static FullHttpRequest toFullHttpRequest(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders) throws Http2Exception Create a new object to contain the request data- Parameters:
streamId
- The stream associated with the requesthttp2Headers
- The initial set of HTTP/2 headers to create the request withalloc
- TheByteBufAllocator
to use to generate the content of the messagevalidateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new request object which represents headers/data
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
-
extractPath
-
toFullHttpRequest
public static FullHttpRequest toFullHttpRequest(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders) throws Http2Exception Create a new object to contain the request data- Parameters:
streamId
- The stream associated with the requesthttp2Headers
- The initial set of HTTP/2 headers to create the request withcontent
-ByteBuf
content to put inFullHttpRequest
validateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new request object which represents headers/data
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
-
toHttpRequest
public static 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 requesthttp2Headers
- The initial set of HTTP/2 headers to create the request withvalidateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new request object which represents headers for a chunked request
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
-
toHttpResponse
public static 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 responsehttp2Headers
- The initial set of HTTP/2 headers to create the response withvalidateHttpHeaders
-true
to validate HTTP headers in the http-codecfalse
not to validate HTTP headers in the http-codec
- Returns:
- A new response object which represents headers for a chunked response
- Throws:
Http2Exception
- seeaddHttp2ToHttpHeaders(int, Http2Headers, HttpHeaders, HttpVersion, boolean, boolean)
-
addHttp2ToHttpHeaders
public static void addHttp2ToHttpHeaders(int streamId, Http2Headers inputHeaders, FullHttpMessage destinationMessage, boolean addToTrailer) throws Http2Exception Translate and add HTTP/2 headers to HTTP/1.x headers.- Parameters:
streamId
- The stream associated withsourceHeaders
.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
public static void addHttp2ToHttpHeaders(int streamId, Http2Headers inputHeaders, HttpHeaders outputHeaders, HttpVersion httpVersion, boolean isTrailer, boolean isRequest) throws Http2Exception Translate and add HTTP/2 headers to HTTP/1.x headers.- Parameters:
streamId
- The stream associated withsourceHeaders
.inputHeaders
- The HTTP/2 headers to convert.outputHeaders
- The object which will contain the resulting HTTP/1.x headers..httpVersion
- What HTTP/1.x versionoutputHeaders
should be treated as when doing the conversion.isTrailer
-true
ifoutputHeaders
should be treated as trailing headers.false
otherwise.isRequest
-true
if theoutputHeaders
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
Converts the given HTTP/1.x headers into HTTP/2 headers. The following headers are only used if they can not be found in from theHOST
header or theRequest-Line
as defined by rfc7230HttpConversionUtil.ExtensionHeaderNames.PATH
is ignored and instead extracted from theRequest-Line
. -
toHttp2Headers
-
toLowercaseMap
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) -
toHttp2HeadersFilterTE
private static void toHttp2HeadersFilterTE(Map.Entry<CharSequence, CharSequence> entry, Http2Headers out) Filter theHttpHeaderNames.TE
header according to the special rules in the HTTP/2 RFC.- Parameters:
entry
- An entry whose name isHttpHeaderNames.TE
.out
- the resulting HTTP/2 headers.
-
toHttp2Headers
-
splitValidCookieHeader
-
toHttp2Path
Generate an HTTP/2 {code :path} from a URI in accordance with rfc7230, 5.3. -
setHttp2Authority
-
setHttp2Scheme
-
setHttp2Scheme
-