use of io.netty.handler.codec.http2.Http2Exception 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.Http2Exception 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.Http2Exception 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());
}
use of io.netty.handler.codec.http2.Http2Exception in project rest.li by linkedin.
the class Http2StreamCodec method onConnectionError.
@Override
protected void onConnectionError(ChannelHandlerContext ctx, boolean outbound, Throwable cause, Http2Exception connectionError) {
// Logs the full exception here
final String message = String.format("HTTP/2 connection encountered an exception, streamCount=%d, remote=%s, channel=%s", connection().numActiveStreams(), ctx.channel().remoteAddress(), ctx.channel().id());
LOG.error(message, cause);
try {
connection().forEachActiveStream(stream -> {
resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
doOnStreamError(ctx, stream.id(), cause);
return true;
});
ctx.flush();
} catch (Http2Exception e) {
LOG.error("Encountered exception while invoking request callbacks with errors", e);
} finally {
super.onConnectionError(ctx, outbound, cause, connectionError);
}
}
use of io.netty.handler.codec.http2.Http2Exception 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;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
responseHeaders = headers;
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
buffer.appendBuffer(Buffer.buffer(data.duplicate()));
if (endOfStream) {
vertx.runOnContext(v -> {
assertEquals("" + length, responseHeaders.get("content-length").toString());
assertEquals(expected, buffer);
complete();
});
}
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