use of io.netty.handler.codec.http2.Http2Headers in project vert.x by eclipse.
the class Http2ServerConnection method createRequest.
private Http2ServerRequest createRequest(int streamId, Http2Headers headers, boolean streamEnded) {
Http2Stream stream = handler.connection().stream(streamId);
String contentEncoding = options.isCompressionSupported() ? HttpUtils.determineContentEncoding(headers) : null;
Http2ServerRequest request = new Http2ServerRequest(this, options.getTracingPolicy(), streamContextSupplier.get(), serverOrigin, headers, contentEncoding, streamEnded);
request.isConnect = request.method() == HttpMethod.CONNECT;
request.init(stream);
return request;
}
use of io.netty.handler.codec.http2.Http2Headers in project rest.li by linkedin.
the class NettyRequestAdapter method toHttp2Headers.
/**
* Extracts fields from a {@link Request} and construct a {@link Http2Headers} instance.
*
* @param request StreamRequest to extract fields from
* @return a new instance of Http2Headers
* @throws {@link Exception}
*/
public static <R extends Request> Http2Headers toHttp2Headers(R request) throws Exception {
URI uri = request.getURI();
URL url = new URL(uri.toString());
String method = request.getMethod();
String authority = url.getAuthority();
String path = url.getFile();
String scheme = uri.getScheme();
// RFC 2616, section 5.1.2:
// Note that the absolute path cannot be empty; if none is present in the original URI,
// it MUST be given as "/" (the server root).
path = path.isEmpty() ? "/" : path;
final Http2Headers headers = new DefaultHttp2Headers().method(method).authority(authority).path(path).scheme(scheme);
for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
// Ignores HTTP/2 blacklisted headers
if (HEADER_BLACKLIST.contains(entry.getKey().toLowerCase())) {
continue;
}
// RFC 7540, section 8.1.2:
// ... header field names MUST be converted to lowercase prior to their
// encoding in HTTP/2. A request or response containing uppercase
// header field names MUST be treated as malformed (Section 8.1.2.6).
String name = entry.getKey().toLowerCase();
String value = entry.getValue();
headers.set(name, value);
}
// Split up cookies to allow for better header compression
headers.set(HttpHeaderNames.COOKIE, request.getCookies());
return headers;
}
use of io.netty.handler.codec.http2.Http2Headers in project rest.li by linkedin.
the class TestNettyRequestAdapter method testStreamToHttp2HeadersCookies.
@Test
public void testStreamToHttp2HeadersCookies() throws Exception {
StreamRequestBuilder streamRequestBuilder = new StreamRequestBuilder(new URI(ANY_URI));
IntStream.range(0, 10).forEach(i -> streamRequestBuilder.addCookie(ANY_COOKIE));
StreamRequest request = streamRequestBuilder.build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(ANY_ENTITY.getBytes()))));
Http2Headers headers = NettyRequestAdapter.toHttp2Headers(request);
Assert.assertNotNull(headers);
List<CharSequence> cookies = headers.getAll(HttpHeaderNames.COOKIE);
Assert.assertNotNull(cookies);
Assert.assertEquals(cookies.size(), 10);
}
use of io.netty.handler.codec.http2.Http2Headers in project rest.li by linkedin.
the class TestNettyRequestAdapter method testStreamToHttp2HeadersBlacklist.
@Test
public void testStreamToHttp2HeadersBlacklist() throws Exception {
StreamRequestBuilder streamRequestBuilder = new StreamRequestBuilder(new URI(ANY_URI));
HEADER_BLACKLIST.forEach(header -> streamRequestBuilder.addHeaderValue(header, ANY_HEADER));
StreamRequest request = streamRequestBuilder.build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(ANY_ENTITY.getBytes()))));
Http2Headers headers = NettyRequestAdapter.toHttp2Headers(request);
Assert.assertNotNull(headers);
HEADER_BLACKLIST.forEach(header -> Assert.assertFalse(headers.contains(header), header));
}
use of io.netty.handler.codec.http2.Http2Headers in project rest.li by linkedin.
the class TestNettyRequestAdapter method testStreamToHttp2HeadersPseudoHeaders.
@Test
public void testStreamToHttp2HeadersPseudoHeaders() throws Exception {
StreamRequestBuilder streamRequestBuilder = new StreamRequestBuilder(new URI(ANY_URI));
StreamRequest request = streamRequestBuilder.build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(ANY_ENTITY.getBytes()))));
Http2Headers headers = NettyRequestAdapter.toHttp2Headers(request);
Assert.assertNotNull(headers);
Assert.assertEquals(headers.authority(), "localhost:8080");
Assert.assertEquals(headers.method(), "GET");
Assert.assertEquals(headers.path(), "/foo/bar?q=baz");
Assert.assertEquals(headers.scheme(), "http");
}
Aggregations