use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ClientTest method testUpdateConnectionWindowSize.
@Test
public void testUpdateConnectionWindowSize() throws Exception {
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(65535, windowSizeIncrement);
testComplete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
}).connectionHandler(conn -> {
assertEquals(65535, conn.getWindowSize());
conn.setWindowSize(65535 + 10000);
assertEquals(65535 + 10000, conn.getWindowSize());
conn.setWindowSize(65535 + 65535);
assertEquals(65535 + 65535, conn.getWindowSize());
}).end();
await();
}
use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ServerTest method testPromiseStreamError.
@Test
public void testPromiseStreamError() throws Exception {
Context ctx = vertx.getOrCreateContext();
waitFor(2);
Promise<Void> when = Promise.promise();
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
assertOnIOContext(ctx);
when.complete();
HttpServerResponse resp = ar.result();
AtomicInteger erros = new AtomicInteger();
resp.exceptionHandler(err -> {
assertOnIOContext(ctx);
erros.incrementAndGet();
});
resp.closeHandler(v -> {
assertOnIOContext(ctx);
assertTrue("Was expecting errors to be > 0", erros.get() > 0);
complete();
});
resp.endHandler(v -> {
assertOnIOContext(ctx);
complete();
});
// Transition to half-closed remote
resp.setChunked(true).write("whatever");
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
when.future().onComplete(ar -> {
Http2ConnectionEncoder encoder = request.encoder;
encoder.frameWriter().writeHeaders(request.context, promisedStreamId, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
}
});
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ServerTest method testUnknownFrame.
@Test
public void testUnknownFrame() throws Exception {
Buffer expectedSend = TestUtils.randomBuffer(500);
Buffer expectedRecv = TestUtils.randomBuffer(500);
Context ctx = vertx.getOrCreateContext();
server.requestHandler(req -> {
req.customFrameHandler(frame -> {
assertOnIOContext(ctx);
assertEquals(10, frame.type());
assertEquals(253, frame.flags());
assertEquals(expectedSend, frame.payload());
req.response().writeCustomFrame(12, 134, expectedRecv).end();
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.decoder.frameListener(new Http2EventAdapter() {
int status = 0;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
int s = status++;
vertx.runOnContext(v -> {
assertEquals(0, s);
});
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload) {
int s = status++;
byte[] tmp = new byte[payload.readableBytes()];
payload.getBytes(payload.readerIndex(), tmp);
Buffer recv = Buffer.buffer().appendBytes(tmp);
vertx.runOnContext(v -> {
assertEquals(1, s);
assertEquals(12, frameType);
assertEquals(134, flags.value());
assertEquals(expectedRecv, recv);
});
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
int len = data.readableBytes();
int s = status++;
vertx.runOnContext(v -> {
assertEquals(2, s);
assertEquals(0, len);
assertTrue(endOfStream);
testComplete();
});
return data.readableBytes() + padding;
}
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.encoder.writeFrame(request.context, (byte) 10, id, new Http2Flags((short) 253), expectedSend.getByteBuf(), request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ServerTest method testTrailers.
@Test
public void testTrailers() throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setChunked(true);
resp.write("some-content");
resp.putTrailer("Foo", "foo_value");
resp.putTrailer("bar", "bar_value");
resp.putTrailer("juu", (List<String>) Arrays.asList("juu_value_1", "juu_value_2"));
resp.end();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
int count;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
switch(count++) {
case 0:
vertx.runOnContext(v -> {
assertFalse(endStream);
});
break;
case 1:
vertx.runOnContext(v -> {
assertEquals("foo_value", headers.get("foo").toString());
assertEquals(1, headers.getAll("foo").size());
assertEquals("foo_value", headers.getAll("foo").get(0).toString());
assertEquals("bar_value", headers.getAll("bar").get(0).toString());
assertEquals(2, headers.getAll("juu").size());
assertEquals("juu_value_1", headers.getAll("juu").get(0).toString());
assertEquals("juu_value_2", headers.getAll("juu").get(1).toString());
assertTrue(endStream);
testComplete();
});
break;
default:
vertx.runOnContext(v -> {
fail();
});
break;
}
}
});
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ServerTest method testSendFile.
private void testSendFile(Buffer expected, String path, long offset, long length) throws Exception {
waitFor(2);
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.bodyEndHandler(v -> {
assertEquals(resp.bytesWritten(), length);
complete();
});
resp.sendFile(path, offset, length);
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
Buffer buffer = Buffer.buffer();
Http2Headers responseHeaders;
private void endStream() {
vertx.runOnContext(v -> {
assertEquals("" + length, responseHeaders.get("content-length").toString());
assertEquals(expected, buffer);
complete();
});
}
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
responseHeaders = headers;
if (endStream) {
endStream();
}
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
buffer.appendBuffer(Buffer.buffer(data.duplicate()));
if (endOfStream) {
endStream();
}
return data.readableBytes() + padding;
}
});
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
Aggregations