use of io.netty.handler.codec.http2.DefaultHttp2Headers in project vert.x by eclipse.
the class Http2ServerTest method testConnect.
@Test
public void testConnect() throws Exception {
server.requestHandler(req -> {
assertEquals(HttpMethod.CONNECT, req.method());
assertEquals("whatever.com", req.host());
assertNull(req.path());
assertNull(req.query());
assertNull(req.scheme());
assertNull(req.uri());
assertNull(req.absoluteURI());
testComplete();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2Headers headers = new DefaultHttp2Headers().method("CONNECT").authority("whatever.com");
request.encoder.writeHeaders(request.context, id, headers, 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers 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.DefaultHttp2Headers 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);
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project netty by netty.
the class Http2MultiplexCodecTest method outboundStreamShouldWriteResetFrameOnClose_headersSent.
@Test
public void outboundStreamShouldWriteResetFrameOnClose_headersSent() {
childChannelInitializer.handler = new ChannelInboundHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()));
ctx.fireChannelActive();
}
};
Http2StreamChannelBootstrap b = new Http2StreamChannelBootstrap();
b.parentChannel(parentChannel).handler(childChannelInitializer);
Channel childChannel = b.connect().channel();
assertTrue(childChannel.isActive());
Http2HeadersFrame headersFrame = parentChannel.readOutbound();
assertNotNull(headersFrame);
assertFalse(Http2CodecUtil.isStreamIdValid(headersFrame.streamId()));
parentChannel.pipeline().fireUserEventTriggered(new Http2StreamActiveEvent(2, headersFrame));
childChannel.close();
parentChannel.runPendingTasks();
Http2ResetFrame reset = parentChannel.readOutbound();
assertEquals(2, reset.streamId());
assertEquals(Http2Error.CANCEL.code(), reset.errorCode());
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project netty by netty.
the class InboundHttp2ToHttpAdapterTest method clientRequestMultipleDataFrames.
@Test
public void clientRequestMultipleDataFrames() throws Exception {
boostrapEnv(1, 1, 1);
final String text = "hello world big time data!";
final ByteBuf content = Unpooled.copiedBuffer(text.getBytes());
final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/path/resource2", content, true);
try {
HttpHeaders httpHeaders = request.headers();
httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/some/path/resource2"));
final int midPoint = text.length() / 2;
runInChannel(clientChannel, new Http2Runnable() {
@Override
public void run() throws Http2Exception {
clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
clientHandler.encoder().writeData(ctxClient(), 3, content.retainedSlice(0, midPoint), 0, false, newPromiseClient());
clientHandler.encoder().writeData(ctxClient(), 3, content.retainedSlice(midPoint, text.length() - midPoint), 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();
}
}
Aggregations