use of io.netty.handler.codec.http2.Http2Headers in project netty by netty.
the class InboundHttp2ToHttpAdapterTest method clientRequestSingleHeaderCookieSplitIntoMultipleEntries.
@Test
public void clientRequestSingleHeaderCookieSplitIntoMultipleEntries() throws Exception {
boostrapEnv(1, 1, 1);
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/path/resource2", true);
try {
HttpHeaders httpHeaders = request.headers();
httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
httpHeaders.set(HttpHeaderNames.HOST, "example.org");
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
httpHeaders.set(HttpHeaderNames.COOKIE, "a=b; c=d; e=f");
httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).scheme(new AsciiString("https")).authority(new AsciiString("example.org")).path(new AsciiString("/some/path/resource2")).add(HttpHeaderNames.COOKIE, "a=b").add(HttpHeaderNames.COOKIE, "c=d").add(HttpHeaderNames.COOKIE, "e=f");
runInChannel(clientChannel, new Http2Runnable() {
@Override
public void run() throws Http2Exception {
clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, true, newPromiseClient());
clientChannel.flush();
}
});
awaitRequests();
ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
verify(serverListener).messageReceived(requestCaptor.capture());
capturedRequests = requestCaptor.getAllValues();
assertEquals(request, capturedRequests.get(0));
} finally {
request.release();
}
}
use of io.netty.handler.codec.http2.Http2Headers in project netty by netty.
the class Http2FrameWriterBenchmark method createHeaders.
private static Http2Headers createHeaders(int numValues, int nameLength, int valueLength) {
Http2Headers headers = new DefaultHttp2Headers();
Random r = new Random();
for (int i = 0; i < numValues; ++i) {
byte[] tmp = new byte[nameLength];
r.nextBytes(tmp);
AsciiString name = new AsciiString(tmp);
tmp = new byte[valueLength];
r.nextBytes(tmp);
headers.add(name, new AsciiString(tmp));
}
return headers;
}
use of io.netty.handler.codec.http2.Http2Headers in project netty by netty.
the class ReadOnlyHttp2HeadersBenchmark method defaultServerHeaders.
@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int defaultServerHeaders() {
Http2Headers headers = new DefaultHttp2Headers(false);
for (int i = 0; i < headerCount; ++i) {
headers.add(headerNames[i], headerValues[i]);
}
headers.status(HttpResponseStatus.OK.codeAsText());
return iterate(headers);
}
use of io.netty.handler.codec.http2.Http2Headers in project netty by netty.
the class HelloWorldHttp2Handler method sendResponse.
/**
* Sends a "Hello World" DATA frame to the client.
*/
private static void sendResponse(ChannelHandlerContext ctx, ByteBuf payload) {
// Send a frame for the response status
Http2Headers headers = new DefaultHttp2Headers().status(OK.codeAsText());
ctx.write(new DefaultHttp2HeadersFrame(headers));
ctx.writeAndFlush(new DefaultHttp2DataFrame(payload, true));
}
use of io.netty.handler.codec.http2.Http2Headers in project netty by netty.
the class HelloWorldHttp2Handler method userEventTriggered.
/**
* Handles the cleartext HTTP upgrade event. If an upgrade occurred, sends a simple response via HTTP/2
* on stream 1 (the stream specifically reserved for cleartext HTTP upgrade).
*/
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) {
// Write an HTTP/2 response to the upgrade request
Http2Headers headers = new DefaultHttp2Headers().status(OK.codeAsText()).set(new AsciiString(UPGRADE_RESPONSE_HEADER), new AsciiString("true"));
encoder().writeHeaders(ctx, 1, headers, 0, true, ctx.newPromise());
}
super.userEventTriggered(ctx, evt);
}
Aggregations