use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ServerTest method test100Continue.
private void test100Continue() throws Exception {
startServer();
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 count = 0;
@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 -> {
assertEquals("100", headers.status().toString());
});
request.encoder.writeData(request.context, id, Buffer.buffer("the-body").getByteBuf(), 0, true, request.context.newPromise());
request.context.flush();
break;
case 1:
vertx.runOnContext(v -> {
assertEquals("200", headers.status().toString());
assertEquals("wibble-value", headers.get("wibble").toString());
testComplete();
});
break;
default:
vertx.runOnContext(v -> {
fail();
});
}
}
});
request.encoder.writeHeaders(request.context, id, GET("/").add("expect", "100-continue"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ServerTest method testPriorKnowledge.
@Test
public void testPriorKnowledge() throws Exception {
server.close();
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST));
server.requestHandler(req -> {
req.response().end("Hello World");
});
startServer();
TestClient client = new TestClient() {
@Override
protected ChannelInitializer channelInitializer(int port, String host, Consumer<Connection> handler) {
return new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
Http2Connection connection = new DefaultHttp2Connection(false);
TestClientHandlerBuilder clientHandlerBuilder = new TestClientHandlerBuilder(handler);
TestClientHandler clientHandler = clientHandlerBuilder.build(connection);
p.addLast(clientHandler);
}
};
}
};
ChannelFuture fut = client.connect(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, request -> {
request.decoder.frameListener(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 -> {
testComplete();
});
}
});
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.Http2Exception in project vert.x by eclipse.
the class Http2ServerTest method test100ContinueRejectedManually.
@Test
public void test100ContinueRejectedManually() throws Exception {
server.requestHandler(req -> {
req.response().setStatusCode(405).end();
req.handler(buf -> {
fail();
});
});
startServer();
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 count = 0;
@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 -> {
assertEquals("405", headers.status().toString());
vertx.setTimer(100, v2 -> {
testComplete();
});
});
break;
default:
vertx.runOnContext(v -> {
fail();
});
}
}
});
request.encoder.writeHeaders(request.context, id, GET("/").add("expect", "100-continue"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testStreamPriority.
/*
@Test
public void testFillsSingleConnection() throws Exception {
Set<HttpConnection> serverConns = new HashSet<>();
List<HttpServerRequest> requests = new ArrayList<>();
server.requestHandler(req -> {
requests.add(req);
serverConns.add(req.connection());
if (requests.size() == 10) {
System.out.println("requestsPerConn = " + serverConns);
}
});
startServer();
client.close();
client = vertx.createHttpClient(new HttpClientOptions(clientOptions).
setHttp2MaxPoolSize(2).
setHttp2MaxStreams(10));
AtomicInteger respCount = new AtomicInteger();
for (int i = 0;i < 10;i++) {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
resp.endHandler(v -> {
});
});
}
await();
}
*/
@Test
public void testStreamPriority() 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(2);
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 -> {
assertEquals(requestStreamPriority.getDependency(), streamDependency);
assertEquals(requestStreamPriority.getWeight(), weight);
assertEquals(requestStreamPriority.isExclusive(), exclusive);
encoder.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), responseStreamPriority.getDependency(), responseStreamPriority.getWeight(), responseStreamPriority.isExclusive(), 0, true, ctx.newPromise());
ctx.flush();
if (endStream)
complete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.request(requestOptions).onComplete(onSuccess(req -> {
req.setStreamPriority(requestStreamPriority).send(onSuccess(resp -> {
assertEquals(responseStreamPriority, resp.request().getStreamPriority());
Context ctx = vertx.getOrCreateContext();
assertOnIOContext(ctx);
resp.endHandler(v -> {
complete();
});
}));
}));
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2Exception in project vert.x by eclipse.
the class Http2ClientTest method testServerStreamPriorityNoChange.
@Ignore("Cannot pass reliably for now (https://github.com/netty/netty/issues/9842)")
@Test
public void testServerStreamPriorityNoChange() throws Exception {
StreamPriority streamPriority = new StreamPriority().setDependency(123).setWeight((short) 45).setExclusive(true);
waitFor(1);
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 {
encoder.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), streamPriority.getDependency(), streamPriority.getWeight(), streamPriority.isExclusive(), 0, false, ctx.newPromise());
encoder.writePriority(ctx, streamId, streamPriority.getDependency(), streamPriority.getWeight(), streamPriority.isExclusive(), ctx.newPromise());
encoder.writeData(ctx, streamId, Buffer.buffer("hello").getByteBuf(), 0, true, ctx.newPromise());
ctx.flush();
}
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive) throws Http2Exception {
fail("Priority frame should not be sent");
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.request(requestOptions).onComplete(onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(streamPriority, resp.request().getStreamPriority());
Context ctx = vertx.getOrCreateContext();
assertOnIOContext(ctx);
resp.streamPriorityHandler(priority -> fail("Stream priority handler should not be called"));
resp.endHandler(v -> {
assertEquals(streamPriority, resp.request().getStreamPriority());
complete();
});
}));
}));
await();
} finally {
s.channel().close().sync();
}
}
Aggregations