public final class ArmeriaHttpUtil extends Object
The conversion between HTTP/1 and HTTP/2 has been forked from Netty's HttpConversionUtil.
| Modifier and Type | Field and Description |
|---|---|
static io.netty.util.AsciiString |
HEADER_NAME_KEEP_ALIVE
The old
"keep-alive" header which has been superceded by "connection". |
static io.netty.util.AsciiString |
HEADER_NAME_PROXY_CONNECTION
The old
"proxy-connection" header which has been superceded by "connection". |
static Charset |
HTTP_DEFAULT_CONTENT_CHARSET
The default HTTP content-type charset.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
concatPaths(String path1,
String path2)
Concatenates two path strings.
|
static String |
decodePath(String path)
Decodes a percent-encoded path string.
|
static boolean |
isAbsoluteUri(String maybeUri)
Returns
true if the specified path is an absolute URI. |
static boolean |
isContentAlwaysEmptyWithValidation(HttpStatus status,
HttpData content,
HttpHeaders trailers)
Returns
true if the content of the response with the given HttpStatus is expected to
be always empty (1xx, 204, 205 and 304 responses.) |
static boolean |
isCorsPreflightRequest(HttpRequest request)
Returns
true if the specified request is a CORS preflight request. |
static boolean |
isInformational(String statusText)
Returns
true if the specified HTTP status string represents an informational status. |
static boolean |
isTrailerBlacklisted(io.netty.util.AsciiString name)
Returns
true if the specified header name is not allowed for HTTP tailers. |
static void |
parseDirectives(String directives,
BiConsumer<String,String> callback)
Parses the specified HTTP header directives and invokes the specified
callback
with the directive names and values. |
static long |
parseDirectiveValueAsSeconds(String value)
Converts the specified HTTP header directive value into a long integer.
|
static ResponseHeaders |
setOrRemoveContentLength(ResponseHeaders headers,
HttpData content,
HttpHeaders trailers)
Returns a
ResponseHeaders whose HttpHeaderNames.CONTENT_LENGTH is added or removed
according to the status of the specified headers, content and trailers. |
static RequestHeaders |
toArmeria(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http.HttpRequest in,
ServerConfig cfg)
Converts the headers of the given Netty HTTP/1.x request into Armeria HTTP/2 headers.
|
static HttpHeaders |
toArmeria(io.netty.handler.codec.http2.Http2Headers headers,
boolean request,
boolean endOfStream)
Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers.
|
static HttpHeaders |
toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders)
Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
|
static void |
toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders,
HttpHeadersBuilder out)
Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
|
static ResponseHeaders |
toArmeria(io.netty.handler.codec.http.HttpResponse in)
Converts the headers of the given Netty HTTP/1.x response into Armeria HTTP/2 headers.
|
static RequestHeaders |
toArmeriaRequestHeaders(io.netty.channel.ChannelHandlerContext ctx,
io.netty.handler.codec.http2.Http2Headers headers,
boolean endOfStream,
String scheme,
ServerConfig cfg)
Converts the specified Netty HTTP/2 into Armeria HTTP/2
RequestHeaders. |
static void |
toNettyHttp1(int streamId,
HttpHeaders 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.http2.Http2Headers |
toNettyHttp2(HttpHeaders in,
boolean server)
Converts the specified Armeria HTTP/2 headers into Netty HTTP/2 headers.
|
public static final Charset HTTP_DEFAULT_CONTENT_CHARSET
Note that we use StandardCharsets.UTF_8 as default because it is common practice even though
it's not the HTTP standard.
public static final io.netty.util.AsciiString HEADER_NAME_KEEP_ALIVE
"keep-alive" header which has been superceded by "connection".public static final io.netty.util.AsciiString HEADER_NAME_PROXY_CONNECTION
"proxy-connection" header which has been superceded by "connection".public static String concatPaths(String path1, String path2)
public static boolean isAbsoluteUri(String maybeUri)
true if the specified path is an absolute URI.public static boolean isInformational(String statusText)
true if the specified HTTP status string represents an informational status.public static boolean isContentAlwaysEmptyWithValidation(HttpStatus status, HttpData content, HttpHeaders trailers)
true if the content of the response with the given HttpStatus is expected to
be always empty (1xx, 204, 205 and 304 responses.)IllegalArgumentException - if the specified content or trailers are
non-empty when the content is always emptypublic static boolean isCorsPreflightRequest(HttpRequest request)
true if the specified request is a CORS preflight request.public static void parseDirectives(String directives, BiConsumer<String,String> callback)
callback
with the directive names and values.public static long parseDirectiveValueAsSeconds(String value)
value is equal to or greater than 0.
-1 otherwise, i.e. if a negative integer or not a number.public static RequestHeaders toArmeriaRequestHeaders(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http2.Http2Headers headers, boolean endOfStream, String scheme, ServerConfig cfg)
RequestHeaders.public static HttpHeaders toArmeria(io.netty.handler.codec.http2.Http2Headers headers, boolean request, boolean endOfStream)
public static RequestHeaders toArmeria(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.HttpRequest in, ServerConfig cfg) throws URISyntaxException
HOST header or the
Request-Line as defined by rfc7230
HttpConversionUtil.ExtensionHeaderNames.SCHEMEHttpConversionUtil.ExtensionHeaderNames.PATH is ignored and instead extracted from the Request-Line.URISyntaxExceptionpublic static ResponseHeaders toArmeria(io.netty.handler.codec.http.HttpResponse in)
public static HttpHeaders toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders)
public static void toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders,
HttpHeadersBuilder out)
public static io.netty.handler.codec.http2.Http2Headers toNettyHttp2(HttpHeaders in, boolean server)
public static void toNettyHttp1(int streamId,
HttpHeaders inputHeaders,
io.netty.handler.codec.http.HttpHeaders outputHeaders,
io.netty.handler.codec.http.HttpVersion httpVersion,
boolean isTrailer,
boolean isRequest)
throws io.netty.handler.codec.http2.Http2Exception
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 trailers.
false otherwise.isRequest - true if the outputHeaders will be used in a request message.
false for response message.io.netty.handler.codec.http2.Http2Exception - If not all HTTP/2 headers can be translated to HTTP/1.x.public static ResponseHeaders setOrRemoveContentLength(ResponseHeaders headers, HttpData content, HttpHeaders trailers)
ResponseHeaders whose HttpHeaderNames.CONTENT_LENGTH is added or removed
according to the status of the specified headers, content and trailers.
The HttpHeaderNames.CONTENT_LENGTH is removed when:
headers is one of informational headers,
HttpStatus.NO_CONTENT or HttpStatus.RESET_CONTENTHttpHeaderNames.CONTENT_LENGTH is added when the state of the specified headers
does not meet the conditions above and HttpHeaderNames.CONTENT_LENGTH is not present
regardless of the fact that the content is empty or not.IllegalArgumentException - if the specified content or trailers are
non-empty when the content is always emptypublic static boolean isTrailerBlacklisted(io.netty.util.AsciiString name)
true if the specified header name is not allowed for HTTP tailers.Copyright © 2020 LeanCloud. All rights reserved.