Package io.netty.handler.codec.http2
Class HttpConversionUtil
- java.lang.Object
-
- io.netty.handler.codec.http2.HttpConversionUtil
-
public final class HttpConversionUtil extends java.lang.ObjectProvides utility methods and constants for the HTTP/2 to HTTP conversion
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpConversionUtil.ExtensionHeaderNamesProvides the HTTP header extensions used to carry HTTP/2 information in HTTP objectsprivate static classHttpConversionUtil.Http2ToHttpHeaderTranslatorUtility which translates HTTP/2 headers to HTTP/1 headers.
-
Field Summary
Fields Modifier and Type Field Description private static AsciiStringEMPTY_REQUEST_PATH[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be/.private static CharSequenceMap<AsciiString>HTTP_TO_HTTP2_HEADER_BLACKLISTThe set of headers that should not be directly copied when converting headers from HTTP to HTTP/2.static HttpMethodOUT_OF_MESSAGE_SEQUENCE_METHODThis will be the method used forHttpRequestobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1static java.lang.StringOUT_OF_MESSAGE_SEQUENCE_PATHThis will be the path used forHttpRequestobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1static HttpResponseStatusOUT_OF_MESSAGE_SEQUENCE_RETURN_CODEThis will be the status code used forHttpResponseobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1
-
Constructor Summary
Constructors Modifier Constructor Description privateHttpConversionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddHttp2ToHttpHeaders(int streamId, Http2Headers inputHeaders, FullHttpMessage destinationMessage, boolean addToTrailer)Translate and add HTTP/2 headers to HTTP/1.x headers.static voidaddHttp2ToHttpHeaders(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 java.lang.StringextractPath(java.lang.CharSequence method, Http2Headers headers)static HttpResponseStatusparseStatus(java.lang.CharSequence status)Apply HTTP/2 rules while translating status code toHttpResponseStatus(package private) static voidsetHttp2Authority(java.lang.String authority, Http2Headers out)private static voidsetHttp2Scheme(HttpHeaders in, Http2Headers out)private static voidsetHttp2Scheme(HttpHeaders in, java.net.URI uri, Http2Headers out)private static voidsplitValidCookieHeader(Http2Headers out, java.lang.CharSequence valueCs)static FullHttpRequesttoFullHttpRequest(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders)Create a new object to contain the request datastatic FullHttpRequesttoFullHttpRequest(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders)Create a new object to contain the request datastatic FullHttpResponsetoFullHttpResponse(int streamId, Http2Headers http2Headers, ByteBufAllocator alloc, boolean validateHttpHeaders)Create a new object to contain the response datastatic FullHttpResponsetoFullHttpResponse(int streamId, Http2Headers http2Headers, ByteBuf content, boolean validateHttpHeaders)Create a new object to contain the response datastatic Http2HeaderstoHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders)static voidtoHttp2Headers(HttpHeaders inHeaders, Http2Headers out)static Http2HeaderstoHttp2Headers(HttpMessage in, boolean validateHeaders)Converts the given HTTP/1.x headers into HTTP/2 headers.private static voidtoHttp2HeadersFilterTE(java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence> entry, Http2Headers out)Filter theHttpHeaderNames.TEheader according to the special rules in the HTTP/2 RFC.private static AsciiStringtoHttp2Path(java.net.URI uri)Generate an HTTP/2 {code :path} from a URI in accordance with rfc7230, 5.3.static HttpRequesttoHttpRequest(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders)Create a new object to contain the request data.static HttpResponsetoHttpResponse(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders)Create a new object to contain the response data.private static CharSequenceMap<AsciiString>toLowercaseMap(java.util.Iterator<? extends java.lang.CharSequence> valuesIter, int arraySizeHint)
-
-
-
Field Detail
-
HTTP_TO_HTTP2_HEADER_BLACKLIST
private static final CharSequenceMap<AsciiString> 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
public static final HttpMethod OUT_OF_MESSAGE_SEQUENCE_METHOD
This will be the method used forHttpRequestobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1
-
OUT_OF_MESSAGE_SEQUENCE_PATH
public static final java.lang.String OUT_OF_MESSAGE_SEQUENCE_PATH
This will be the path used forHttpRequestobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1- See Also:
- Constant Field Values
-
OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE
public static final HttpResponseStatus OUT_OF_MESSAGE_SEQUENCE_RETURN_CODE
This will be the status code used forHttpResponseobjects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1
-
EMPTY_REQUEST_PATH
private static final AsciiString EMPTY_REQUEST_PATH
[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be/.
-
-
Method Detail
-
parseStatus
public static HttpResponseStatus parseStatus(java.lang.CharSequence status) throws Http2Exception
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- TheByteBufAllocatorto use to generate the content of the messagevalidateHttpHeaders-trueto validate HTTP headers in the http-codecfalsenot 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-ByteBufcontent to put inFullHttpResponsevalidateHttpHeaders-trueto validate HTTP headers in the http-codecfalsenot 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- TheByteBufAllocatorto use to generate the content of the messagevalidateHttpHeaders-trueto validate HTTP headers in the http-codecfalsenot 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
private static java.lang.String extractPath(java.lang.CharSequence method, Http2Headers headers)
-
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-ByteBufcontent to put inFullHttpRequestvalidateHttpHeaders-trueto validate HTTP headers in the http-codecfalsenot 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-trueto validate HTTP headers in the http-codecfalsenot 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-trueto validate HTTP headers in the http-codecfalsenot 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 Http2ExceptionTranslate 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-trueto add to trailing headers.falseto 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, HttpHeaders outputHeaders, HttpVersion httpVersion, boolean isTrailer, boolean isRequest) throws Http2ExceptionTranslate 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 versionoutputHeadersshould be treated as when doing the conversion.isTrailer-trueifoutputHeadersshould be treated as trailing headers.falseotherwise.isRequest-trueif theoutputHeaderswill be used in a request message.falsefor response message.- Throws:
Http2Exception- If not all HTTP/2 headers can be translated to HTTP/1.x.
-
toHttp2Headers
public static Http2Headers toHttp2Headers(HttpMessage in, boolean validateHeaders)
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 theHOSTheader or theRequest-Lineas defined by rfc7230HttpConversionUtil.ExtensionHeaderNames.PATHis ignored and instead extracted from theRequest-Line.
-
toHttp2Headers
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders)
-
toLowercaseMap
private static CharSequenceMap<AsciiString> toLowercaseMap(java.util.Iterator<? extends java.lang.CharSequence> valuesIter, int arraySizeHint)
-
toHttp2HeadersFilterTE
private static void toHttp2HeadersFilterTE(java.util.Map.Entry<java.lang.CharSequence,java.lang.CharSequence> entry, Http2Headers out)Filter theHttpHeaderNames.TEheader 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
public static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out)
-
splitValidCookieHeader
private static void splitValidCookieHeader(Http2Headers out, java.lang.CharSequence valueCs)
-
toHttp2Path
private static AsciiString toHttp2Path(java.net.URI uri)
Generate an HTTP/2 {code :path} from a URI in accordance with rfc7230, 5.3.
-
setHttp2Authority
static void setHttp2Authority(java.lang.String authority, Http2Headers out)
-
setHttp2Scheme
private static void setHttp2Scheme(HttpHeaders in, Http2Headers out)
-
setHttp2Scheme
private static void setHttp2Scheme(HttpHeaders in, java.net.URI uri, Http2Headers out)
-
-