use of io.netty.handler.codec.http2.Http2Headers 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.Http2Headers 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.Http2Headers in project vert.x by eclipse.
the class Http2ServerTest method testMalformedRequestHeaders.
private void testMalformedRequestHeaders(Http2Headers headers) throws Exception {
server.requestHandler(req -> fail());
startServer();
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, headers, 0, true, request.context.newPromise());
request.decoder.frameListener(new Http2FrameAdapter() {
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception {
vertx.runOnContext(v -> {
testComplete();
});
}
});
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2Headers in project vert.x by eclipse.
the class Http2ServerTest method testNetSocketHandleReset.
@Test
public void testNetSocketHandleReset() throws Exception {
server.requestHandler(req -> {
req.toNetSocket().onComplete(onSuccess(socket -> {
AtomicInteger status = new AtomicInteger();
socket.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
StreamResetException ex = (StreamResetException) err;
assertEquals(0, ex.getCode());
assertEquals(0, status.getAndIncrement());
});
socket.endHandler(v -> {
// fail();
});
socket.closeHandler(v -> {
assertEquals(1, status.getAndIncrement());
testComplete();
});
}));
});
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 {
int c = count++;
vertx.runOnContext(v -> {
assertEquals(0, c);
});
request.encoder.writeRstStream(ctx, streamId, 0, ctx.newPromise());
request.context.flush();
}
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.handler.codec.http2.Http2Headers in project vert.x by eclipse.
the class Http2ClientConnection method onPushPromiseRead.
@Override
public synchronized void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
StreamImpl stream = (StreamImpl) stream(streamId);
if (stream != null) {
Handler<HttpClientPush> pushHandler = stream.pushHandler;
if (pushHandler != null) {
Http2Stream promisedStream = handler.connection().stream(promisedStreamId);
StreamImpl pushStream = new StreamImpl(this, context, true);
pushStream.init(promisedStream);
HttpClientPush push = new HttpClientPush(headers, pushStream);
if (metrics != null) {
Object metric = metrics.requestBegin(headers.path().toString(), push);
pushStream.metric = metric;
metrics.requestEnd(metric, 0L);
}
stream.context.dispatch(push, pushHandler);
return;
}
}
Http2ClientConnection.this.handler.writeReset(promisedStreamId, Http2Error.CANCEL.code());
}
Aggregations