use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testStreamError.
@Test
public void testStreamError() throws Exception {
waitFor(3);
ServerBootstrap bootstrap = createH2Server((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, false, ctx.newPromise());
// Send a corrupted frame on purpose to check we get the corresponding error in the request exception handler
// the error is : greater padding value 0c -> 1F
// ChannelFuture a = encoder.frameWriter().writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 12, false, request.context.newPromise());
// normal frame : 00 00 12 00 08 00 00 00 03 0c 68 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 00
// corrupted frame : 00 00 12 00 08 00 00 00 03 1F 68 65 6c 6c 6f 00 00 00 00 00 00 00 00 00 00 00 00
ctx.channel().write(Buffer.buffer(new byte[] { 0x00, 0x00, 0x12, 0x00, 0x08, 0x00, 0x00, 0x00, (byte) (streamId & 0xFF), 0x1F, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }).getByteBuf());
ctx.flush();
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.close();
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v -> {
client = vertx.createHttpClient(createBaseClientOptions());
client.connectionHandler(conn -> {
conn.exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof Http2Exception) {
complete();
}
});
});
client.request(new RequestOptions().setMethod(HttpMethod.PUT).setHost(DEFAULT_HTTPS_HOST).setPort(DEFAULT_HTTPS_PORT).setURI(DEFAULT_TEST_URI)).onComplete(onSuccess(req -> {
req.response(onSuccess(resp -> {
resp.exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof Http2Exception) {
complete();
}
});
})).exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof Http2Exception) {
complete();
}
}).sendHead();
}));
});
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testGet.
@Test
public void testGet() throws Exception {
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
vertx.runOnContext(v -> {
assertTrue(endStream);
encoder.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise());
ctx.flush();
});
}
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
testComplete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.request(requestOptions).onComplete(onSuccess(req -> {
req.send(onSuccess(resp -> {
Context ctx = vertx.getOrCreateContext();
assertOnIOContext(ctx);
resp.endHandler(v -> {
assertOnIOContext(ctx);
resp.request().connection().close();
});
}));
}));
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testClearText.
private void testClearText(boolean upgrade) throws Exception {
Assume.assumeTrue(testAddress.isInetSocket());
ServerBootstrap bootstrap = createH2CServer((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), 0, true, ctx.newPromise());
ctx.flush();
}
}, upgrade);
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.close();
client = vertx.createHttpClient(clientOptions.setUseAlpn(false).setSsl(false).setHttp2ClearTextUpgrade(upgrade));
client.request(requestOptions).onComplete(onSuccess(req1 -> {
req1.send(onSuccess(resp1 -> {
HttpConnection conn = resp1.request().connection();
assertEquals(HttpVersion.HTTP_2, resp1.version());
client.request(requestOptions).onComplete(onSuccess(req2 -> {
req2.send(onSuccess(resp2 -> {
assertSame(((HttpClientConnection) conn).channel(), ((HttpClientConnection) resp2.request().connection()).channel());
testComplete();
}));
}));
}));
}));
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testInvalidServerResponse.
@Test
public void testInvalidServerResponse() throws Exception {
ServerBootstrap bootstrap = createH2Server((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("xyz"), 0, false, ctx.newPromise());
ctx.flush();
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
Context ctx = vertx.getOrCreateContext();
client.close();
ctx.runOnContext(v -> {
client = vertx.createHttpClient(createBaseClientOptions());
client.connectionHandler(conn -> {
conn.exceptionHandler(err -> fail());
});
client.request(requestOptions).onComplete(onSuccess(req -> {
req.send(onFailure(err -> {
assertOnIOContext(ctx);
if (err instanceof NumberFormatException) {
testComplete();
}
}));
}));
});
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2Exception 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.connectionHandler(conn -> {
assertEquals(65535, conn.getWindowSize());
conn.setWindowSize(65535 + 10000);
assertEquals(65535 + 10000, conn.getWindowSize());
conn.setWindowSize(65535 + 65535);
assertEquals(65535 + 65535, conn.getWindowSize());
});
client.request(requestOptions).onComplete(onSuccess(HttpClientRequest::send));
await();
}
Aggregations