Top Description Inners Fields Constructors Methods
io.netty5.handler.codec.http2

public final Class HttpConversionUtil

extends Object
Class Inheritance
Annotations
@UnstableApi
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.handler.codec.UnsupportedValueConverter, io.netty5.handler.codec.http.DefaultFullHttpRequest, .DefaultFullHttpResponse, .DefaultHttpRequest, .DefaultHttpResponse, .FullHttpMessage, .FullHttpRequest, .FullHttpResponse, .HttpHeaderNames, .HttpMessage, .HttpMethod, .HttpRequest, .HttpResponse, .HttpResponseStatus, .HttpUtil, .HttpVersion, io.netty5.handler.codec.http.headers.HttpHeaders, io.netty5.handler.codec.http2.headers.Http2Headers, io.netty5.util.AsciiString, io.netty5.util.internal.StringUtil, .UnstableApi, java.net.URI, java.util.Iterator, .List, .Map.Entry

Provides utility methods and constants for the HTTP/2 to HTTP conversion

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
HttpConversionUtil.ExtensionHeaderNames

Provides the HTTP header extensions used to carry HTTP/2 information in HTTP objects

private static class
HttpConversionUtil.Http2ToHttpHeaderTranslator

Utility which translates HTTP/2 headers to HTTP/1 headers.

Field Summary

Modifier and TypeField and Description
private static final AsciiString
EMPTY_REQUEST_PATH

[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be /.

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.

public static final 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

public static final String
OUT_OF_MESSAGE_SEQUENCE_PATH

This will be the path used for HttpRequest objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1

public static final 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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
addHttp2ToHttpHeaders(int
The stream associated with sourceHeaders.
streamId
,
Http2Headers
The HTTP/2 headers to convert.
inputHeaders
,
FullHttpMessage<R extends FullHttpMessage<R>>
The object which will contain the resulting HTTP/1.x headers.
destinationMessage
,
boolean
true to add to trailing headers. false to add to initial headers.
addToTrailer
)

Translate and add HTTP/2 headers to HTTP/1.x headers.

public static void
addHttp2ToHttpHeaders(int
The stream associated with sourceHeaders.
streamId
,
Http2Headers
The HTTP/2 headers to convert.
inputHeaders
,
HttpHeaders
The object which will contain the resulting HTTP/1.x headers..
outputHeaders
,
HttpVersion
What HTTP/1.x version outputHeaders should be treated as when doing the conversion.
httpVersion
,
boolean
true if outputHeaders should be treated as trailing headers. false otherwise.
isTrailer
,
boolean
true if the outputHeaders will be used in a request message. false for response message.
isRequest
)

Translate and add HTTP/2 headers to HTTP/1.x headers.

private static CharSequence
public static HttpResponseStatus

Returns:

The HTTP/1.x status
parseStatus
(CharSequence
The status from an HTTP/2 frame
status
)

Apply HTTP/2 rules while translating status code to HttpResponseStatus

pack-priv static void
private static void
private static void
public static FullHttpRequest

Returns:

A new request object which represents headers/data
toFullHttpRequest
(int
The stream associated with the request
streamId
,
Http2Headers
The initial set of HTTP/2 headers to create the request with
http2Headers
,
BufferAllocator
The BufferAllocator to use to generate the content of the message
alloc
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
)

Create a new object to contain the request data

public static FullHttpRequest

Returns:

A new request object which represents headers/data
toFullHttpRequest
(int
The stream associated with the request
streamId
,
Http2Headers
The initial set of HTTP/2 headers to create the request with
http2Headers
,
Buffer
Buffer content to put in FullHttpRequest
content
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
,
BufferAllocator allocator)

Create a new object to contain the request data

public static FullHttpResponse

Returns:

A new response object which represents headers/data
toFullHttpResponse
(int
The stream associated with the response
streamId
,
Http2Headers
The initial set of HTTP/2 headers to create the response with
http2Headers
,
BufferAllocator
The BufferAllocator to use to generate the content of the message
alloc
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
)

Create a new object to contain the response data

public static FullHttpResponse

Returns:

A new response object which represents headers/data
toFullHttpResponse
(int
The stream associated with the response
streamId
,
Http2Headers
The initial set of HTTP/2 headers to create the response with
http2Headers
,
Buffer
Buffer content to put in FullHttpResponse
content
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
)

Create a new object to contain the response data

public static Http2Headers
toHttp2Headers(HttpMessage in, boolean validateHeaders)

Converts the given HTTP/1.x headers into HTTP/2 headers.

public static Http2Headers
toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders)

public static void
private static void
toHttp2HeadersFilterTE(Map.Entry<CharSequence, CharSequence>
An entry whose name is HttpHeaderNames#TE.
entry
,
Http2Headers
the resulting HTTP/2 headers.
out
)

Filter the HttpHeaderNames#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.

public static HttpRequest

Returns:

A new request object which represents headers for a chunked request
toHttpRequest
(int
The stream associated with the request
streamId
,
Http2Headers
The initial set of HTTP/2 headers to create the request with
http2Headers
,
boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
)

Create a new object to contain the request data.

public static HttpResponse

Returns:

A new response object which represents headers for a chunked response
toHttpResponse
(final int
The stream associated with the response
streamId
,
final Http2Headers
The initial set of HTTP/2 headers to create the response with
http2Headers
,
final boolean
  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
validateHttpHeaders
)

Create a new object to contain the response data.

private static CharSequenceMap<AsciiString>
toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_REQUEST_PATHback to summary
private static final AsciiString EMPTY_REQUEST_PATH

[RFC 7540], 8.1.2.3 states the path must not be empty, and instead should be /.

HTTP_TO_HTTP2_HEADER_BLACKLISTback to summary
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_METHODback to summary
public static final 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_PATHback to summary
public static final String OUT_OF_MESSAGE_SEQUENCE_PATH

This will be the path used for HttpRequest objects generated out of the HTTP message flow defined in [RFC 7540], Section 8.1

OUT_OF_MESSAGE_SEQUENCE_RETURN_CODEback to summary
public static final 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

Constructor Detail

HttpConversionUtilback to summary
private HttpConversionUtil()

Method Detail

addHttp2ToHttpHeadersback to summary
public static void addHttp2ToHttpHeaders(int streamId, Http2Headers inputHeaders, FullHttpMessage<R extends FullHttpMessage<R>> destinationMessage, boolean addToTrailer) throws Http2Exception

Translate and add HTTP/2 headers to HTTP/1.x headers.

Parameters
streamId:int

The stream associated with sourceHeaders.

inputHeaders:Http2Headers

The HTTP/2 headers to convert.

destinationMessage:FullHttpMessage<R extends FullHttpMessage<R>>

The object which will contain the resulting HTTP/1.x headers.

addToTrailer:boolean

true to add to trailing headers. false to add to initial headers.

Exceptions
Http2Exception:
If not all HTTP/2 headers can be translated to HTTP/1.x.
See Also
addHttp2ToHttpHeaders(int, Http2Headers, HttpHeaders, HttpVersion, boolean, boolean)
addHttp2ToHttpHeadersback to summary
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:int

The stream associated with sourceHeaders.

inputHeaders:Http2Headers

The HTTP/2 headers to convert.

outputHeaders:HttpHeaders

The object which will contain the resulting HTTP/1.x headers..

httpVersion:HttpVersion

What HTTP/1.x version outputHeaders should be treated as when doing the conversion.

isTrailer:boolean

true if outputHeaders should be treated as trailing headers. false otherwise.

isRequest:boolean

true if the outputHeaders will be used in a request message. false for response message.

Exceptions
Http2Exception:
If not all HTTP/2 headers can be translated to HTTP/1.x.
extractPathback to summary
private static CharSequence extractPath(CharSequence method, Http2Headers headers)
parseStatusback to summary
public static HttpResponseStatus parseStatus(CharSequence status) throws Http2Exception

Apply HTTP/2 rules while translating status code to HttpResponseStatus

Parameters
status:CharSequence

The status from an HTTP/2 frame

Returns:HttpResponseStatus

The HTTP/1.x status

Exceptions
Http2Exception:
If there is a problem translating from HTTP/2 to HTTP/1.x
setHttp2Authorityback to summary
pack-priv static void setHttp2Authority(CharSequence authority, Http2Headers out)
setHttp2Schemeback to summary
private static void setHttp2Scheme(HttpHeaders in, Http2Headers out)
setHttp2Schemeback to summary
private static void setHttp2Scheme(HttpHeaders in, URI uri, Http2Headers out)
toFullHttpRequestback to summary
public static FullHttpRequest toFullHttpRequest(int streamId, Http2Headers http2Headers, BufferAllocator alloc, boolean validateHttpHeaders) throws Http2Exception

Create a new object to contain the request data

Parameters
streamId:int

The stream associated with the request

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the request with

alloc:BufferAllocator

The BufferAllocator to use to generate the content of the message

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:FullHttpRequest

A new request object which represents headers/data

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
toFullHttpRequestback to summary
public static FullHttpRequest toFullHttpRequest(int streamId, Http2Headers http2Headers, Buffer content, boolean validateHttpHeaders, BufferAllocator allocator) throws Http2Exception

Create a new object to contain the request data

Parameters
streamId:int

The stream associated with the request

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the request with

content:Buffer

Buffer content to put in FullHttpRequest

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:FullHttpRequest

A new request object which represents headers/data

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
toFullHttpResponseback to summary
public static FullHttpResponse toFullHttpResponse(int streamId, Http2Headers http2Headers, BufferAllocator alloc, boolean validateHttpHeaders) throws Http2Exception

Create a new object to contain the response data

Parameters
streamId:int

The stream associated with the response

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the response with

alloc:BufferAllocator

The BufferAllocator to use to generate the content of the message

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:FullHttpResponse

A new response object which represents headers/data

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
toFullHttpResponseback to summary
public static FullHttpResponse toFullHttpResponse(int streamId, Http2Headers http2Headers, Buffer content, boolean validateHttpHeaders) throws Http2Exception

Create a new object to contain the response data

Parameters
streamId:int

The stream associated with the response

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the response with

content:Buffer

Buffer content to put in FullHttpResponse

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:FullHttpResponse

A new response object which represents headers/data

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
toHttp2Headersback to summary
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 the HOST header or the Request-Line as defined by rfc7230

ExtensionHeaderNames#PATH is ignored and instead extracted from the Request-Line.
toHttp2Headersback to summary
public static Http2Headers toHttp2Headers(HttpHeaders inHeaders, boolean validateHeaders)
toHttp2Headersback to summary
public static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out)
toHttp2HeadersFilterTEback to summary
private static void toHttp2HeadersFilterTE(Map.Entry<CharSequence, CharSequence> entry, Http2Headers out)

Filter the HttpHeaderNames#TE header according to the special rules in the HTTP/2 RFC.

Parameters
entry:Map.Entry<CharSequence, CharSequence>

An entry whose name is HttpHeaderNames#TE.

out:Http2Headers

the resulting HTTP/2 headers.

toHttp2Pathback to summary
private static AsciiString toHttp2Path(URI uri)

Generate an HTTP/2 {code :path} from a URI in accordance with rfc7230, 5.3.

toHttpRequestback to summary
public static HttpRequest toHttpRequest(int streamId, Http2Headers http2Headers, boolean validateHttpHeaders) throws Http2Exception

Create a new object to contain the request data.

Parameters
streamId:int

The stream associated with the request

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the request with

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:HttpRequest

A new request object which represents headers for a chunked request

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, FullHttpMessage, boolean)
toHttpResponseback to summary
public static HttpResponse toHttpResponse(final int streamId, final Http2Headers http2Headers, final boolean validateHttpHeaders) throws Http2Exception

Create a new object to contain the response data.

Parameters
streamId:int

The stream associated with the response

http2Headers:Http2Headers

The initial set of HTTP/2 headers to create the response with

validateHttpHeaders:boolean

  • true to validate HTTP headers in the http-codec
  • false not to validate HTTP headers in the http-codec
Returns:HttpResponse

A new response object which represents headers for a chunked response

Exceptions
Http2Exception:
see addHttp2ToHttpHeaders(int, Http2Headers, HttpHeaders, HttpVersion, boolean, boolean)
toLowercaseMapback to summary
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint)
io.netty5.handler.codec.http2 back to summary

public final Enum HttpConversionUtil.ExtensionHeaderNames

extends Enum<HttpConversionUtil.ExtensionHeaderNames>
Class Inheritance

Provides the HTTP header extensions used to carry HTTP/2 information in HTTP objects

Field Summary

Modifier and TypeField and Description
public static final HttpConversionUtil.ExtensionHeaderNames
PATH

HTTP extension header which will identify the path pseudo header from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-path"

public static final HttpConversionUtil.ExtensionHeaderNames
SCHEME

HTTP extension header which will identify the scheme pseudo header from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-scheme"

public static final HttpConversionUtil.ExtensionHeaderNames
STREAM_DEPENDENCY_ID

HTTP extension header which will identify the stream id which this stream is dependent on.

public static final HttpConversionUtil.ExtensionHeaderNames
STREAM_ID

HTTP extension header which will identify the stream id from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-stream-id"

public static final HttpConversionUtil.ExtensionHeaderNames
STREAM_PROMISE_ID

HTTP extension header which will identify the stream id used to create this stream in an HTTP/2 push promise frame

"x-http2-stream-promise-id"

public static final HttpConversionUtil.ExtensionHeaderNames
STREAM_WEIGHT

HTTP extension header which will identify the weight (if non-default and the priority is not on the default stream) of the associated HTTP/2 stream responsible responsible for generating an HttpObject

"x-http2-stream-weight"

private final AsciiString

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public AsciiString
text()

public static HttpConversionUtil.ExtensionHeaderNames
public static HttpConversionUtil.ExtensionHeaderNames[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

PATHback to summary
public static final HttpConversionUtil.ExtensionHeaderNames PATH

HTTP extension header which will identify the path pseudo header from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-path"

SCHEMEback to summary
public static final HttpConversionUtil.ExtensionHeaderNames SCHEME

HTTP extension header which will identify the scheme pseudo header from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-scheme"

STREAM_DEPENDENCY_IDback to summary
public static final HttpConversionUtil.ExtensionHeaderNames STREAM_DEPENDENCY_ID

HTTP extension header which will identify the stream id which this stream is dependent on. This stream will be a child node of the stream id associated with this header value.

"x-http2-stream-dependency-id"

STREAM_IDback to summary
public static final HttpConversionUtil.ExtensionHeaderNames STREAM_ID

HTTP extension header which will identify the stream id from the HTTP/2 event(s) responsible for generating an HttpObject

"x-http2-stream-id"

STREAM_PROMISE_IDback to summary
public static final HttpConversionUtil.ExtensionHeaderNames STREAM_PROMISE_ID

HTTP extension header which will identify the stream id used to create this stream in an HTTP/2 push promise frame

"x-http2-stream-promise-id"

STREAM_WEIGHTback to summary
public static final HttpConversionUtil.ExtensionHeaderNames STREAM_WEIGHT

HTTP extension header which will identify the weight (if non-default and the priority is not on the default stream) of the associated HTTP/2 stream responsible responsible for generating an HttpObject

"x-http2-stream-weight"

textback to summary
private final AsciiString text

Constructor Detail

ExtensionHeaderNamesback to summary
private ExtensionHeaderNames(String text)

Method Detail

textback to summary
public AsciiString text()
valueOfback to summary
public static HttpConversionUtil.ExtensionHeaderNames valueOf(String name)
valuesback to summary
public static HttpConversionUtil.ExtensionHeaderNames[] values()
io.netty5.handler.codec.http2 back to summary

private final Class HttpConversionUtil.Http2ToHttpHeaderTranslator

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty5.handler.codec.http2.HttpConversionUtil.Http2ToHttpHeaderTranslator

Utility which translates HTTP/2 headers to HTTP/1 headers.

Field Summary

Modifier and TypeField and Description
private final HttpHeaders
private static final CharSequenceMap<AsciiString>
REQUEST_HEADER_TRANSLATIONS

Translations from HTTP/2 header name to the HTTP/1.x equivalent.

private static final CharSequenceMap<AsciiString>
private final int
private final CharSequenceMap<AsciiString>

Constructor Summary

AccessConstructor and Description
pack-priv
Http2ToHttpHeaderTranslator(int streamId, HttpHeaders
The HTTP/1.x headers object to store the results of the translation
output
,
boolean
if true, translates headers using the request translation map. Otherwise uses the response translation map.
request
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

outputback to summary
private final HttpHeaders output
REQUEST_HEADER_TRANSLATIONSback to summary
private static final CharSequenceMap<AsciiString> REQUEST_HEADER_TRANSLATIONS

Translations from HTTP/2 header name to the HTTP/1.x equivalent.

RESPONSE_HEADER_TRANSLATIONSback to summary
private static final CharSequenceMap<AsciiString> RESPONSE_HEADER_TRANSLATIONS
streamIdback to summary
private final int streamId
translationsback to summary
private final CharSequenceMap<AsciiString> translations

Constructor Detail

Http2ToHttpHeaderTranslatorback to summary
pack-priv Http2ToHttpHeaderTranslator(int streamId, HttpHeaders output, boolean request)

Create a new instance

Parameters
output:HttpHeaders

The HTTP/1.x headers object to store the results of the translation

request:boolean

if true, translates headers using the request translation map. Otherwise uses the response translation map.

Method Detail

translateHeadersback to summary
pack-priv void translateHeaders(Iterable<Map.Entry<CharSequence, CharSequence>> inputHeaders) throws Http2Exception