use of io.netty.handler.codec.http2.Http2FrameAdapter in project netty by netty.
the class Http2FrameWriterBenchmark method boostrapEmbeddedEnv.
private static Environment boostrapEmbeddedEnv(final EnvironmentType environmentType) {
final ByteBufAllocator alloc = environmentType.params().clientAllocator();
final EmbeddedEnvironment env = new EmbeddedEnvironment(new DefaultHttp2FrameWriter());
final Http2Connection connection = new DefaultHttp2Connection(false);
Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, env.writer());
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, new DefaultHttp2FrameReader());
Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).frameListener(new Http2FrameAdapter()).codec(decoder, encoder).build();
env.context(new EmbeddedChannelWriteReleaseHandlerContext(alloc, connectionHandler) {
@Override
protected void handleException(Throwable t) {
handleUnexpectedException(t);
}
});
return env;
}
use of io.netty.handler.codec.http2.Http2FrameAdapter in project vert.x by eclipse.
the class Http2ServerTest method testResetActivePushPromise.
@Test
public void testResetActivePushPromise() throws Exception {
Context ctx = vertx.getOrCreateContext();
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
assertOnIOContext(ctx);
HttpServerResponse response = ar.result();
AtomicInteger resets = new AtomicInteger();
response.exceptionHandler(err -> {
if (err instanceof StreamResetException) {
assertEquals(8, ((StreamResetException) err).getCode());
resets.incrementAndGet();
}
});
response.closeHandler(v -> {
testComplete();
assertEquals(1, resets.get());
});
response.setChunked(true).write("some_content");
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.decoder.frameListener(new Http2FrameAdapter() {
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
request.encoder.writeRstStream(ctx, streamId, Http2Error.CANCEL.code(), ctx.newPromise());
request.context.flush();
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2FrameAdapter in project vert.x by eclipse.
the class Http2ServerTest method testQueuePushPromise.
@Test
public void testQueuePushPromise() throws Exception {
Context ctx = vertx.getOrCreateContext();
int numPushes = 10;
Set<String> pushSent = new HashSet<>();
server.requestHandler(req -> {
req.response().setChunked(true).write("abc");
for (int i = 0; i < numPushes; i++) {
int val = i;
String path = "/wibble" + val;
req.response().push(HttpMethod.GET, path, ar -> {
assertTrue(ar.succeeded());
assertSameEventLoop(ctx, Vertx.currentContext());
pushSent.add(path);
vertx.setTimer(10, id -> {
ar.result().end("wibble-" + val);
});
});
}
});
startServer(ctx);
TestClient client = new TestClient();
client.settings.maxConcurrentStreams(3);
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.decoder.frameListener(new Http2FrameAdapter() {
int count = numPushes;
Set<String> pushReceived = new HashSet<>();
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
pushReceived.add(headers.path().toString());
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
if (count-- == 0) {
vertx.runOnContext(v -> {
assertEquals(numPushes, pushSent.size());
assertEquals(pushReceived, pushSent);
testComplete();
});
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2FrameAdapter in project vert.x by eclipse.
the class Http2ServerTest method testResetPendingPushPromise.
@Test
public void testResetPendingPushPromise() throws Exception {
Context ctx = vertx.getOrCreateContext();
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertFalse(ar.succeeded());
assertOnIOContext(ctx);
testComplete();
});
});
startServer(ctx);
TestClient client = new TestClient();
client.settings.maxConcurrentStreams(0);
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.decoder.frameListener(new Http2FrameAdapter() {
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
request.encoder.writeRstStream(request.context, promisedStreamId, Http2Error.CANCEL.code(), request.context.newPromise());
request.context.flush();
}
});
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2FrameAdapter in project vert.x by eclipse.
the class Http2ServerTest method testStreamPriorityNoChange.
@Test
public void testStreamPriorityNoChange() throws Exception {
StreamPriority requestStreamPriority = new StreamPriority().setDependency(123).setWeight((short) 45).setExclusive(true);
StreamPriority responseStreamPriority = new StreamPriority().setDependency(153).setWeight((short) 75).setExclusive(false);
waitFor(4);
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
assertEquals(requestStreamPriority, req.streamPriority());
req.bodyHandler(b -> {
assertEquals(requestStreamPriority, req.streamPriority());
resp.setStatusCode(200);
resp.setStreamPriority(responseStreamPriority);
resp.write("hello");
resp.setStreamPriority(responseStreamPriority);
resp.end("world");
complete();
});
req.streamPriorityHandler(streamPriority -> {
fail("Stream priority handler should not be called");
});
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), requestStreamPriority.getDependency(), requestStreamPriority.getWeight(), requestStreamPriority.isExclusive(), 0, false, request.context.newPromise());
request.context.flush();
request.encoder.writePriority(request.context, id, requestStreamPriority.getDependency(), requestStreamPriority.getWeight(), requestStreamPriority.isExclusive(), request.context.newPromise());
request.context.flush();
request.encoder.writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 0, true, request.context.newPromise());
request.context.flush();
request.decoder.frameListener(new Http2FrameAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
super.onHeadersRead(ctx, streamId, headers, streamDependency, weight, exclusive, padding, endStream);
vertx.runOnContext(v -> {
assertEquals(id, streamId);
assertEquals(responseStreamPriority.getDependency(), streamDependency);
assertEquals(responseStreamPriority.getWeight(), weight);
assertEquals(responseStreamPriority.isExclusive(), exclusive);
complete();
});
}
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(id, streamId);
assertEquals(responseStreamPriority.getDependency(), streamDependency);
assertEquals(responseStreamPriority.getWeight(), weight);
assertEquals(responseStreamPriority.isExclusive(), exclusive);
complete();
});
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
if (endOfStream) {
vertx.runOnContext(v -> {
complete();
});
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
});
fut.sync();
await();
}
Aggregations