Skip to content

Commit

Permalink
Non keep-alive HTTP/1.x requests close the connection immediately wit…
Browse files Browse the repository at this point in the history
…h compressed responses - fixes #2184
  • Loading branch information
vietj committed Oct 27, 2017
1 parent eb5d53c commit 1ea29f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -31,7 +31,13 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
if (msg instanceof ByteBuf) {
// convert ByteBuf to HttpContent to make it work with compression. This is needed as we use the
// ChunkedWriteHandler to send files when compression is enabled.
msg = new DefaultHttpContent((ByteBuf) msg);
ByteBuf buff = (ByteBuf) msg;
if (buff.isReadable()) {
// We only encode non empty buffers, as empty buffers can be used for determining when
// the content has been flushed and it confuses the HttpContentCompressor
// if we let it go
msg = new DefaultHttpContent(buff);
}
}
super.write(ctx, msg, promise);
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/io/vertx/test/core/Http1xTest.java
Expand Up @@ -3722,4 +3722,27 @@ public void testIdleTimeoutWithPartialH2CRequest() throws Exception {
}));
await();
}

@Test
public void testCompressedResponseWithConnectionCloseAndNoCompressionHeader() throws Exception {
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(2048));
server.close();
server = vertx.createHttpServer(new HttpServerOptions()
.setPort(DEFAULT_HTTP_PORT)
.setHost(DEFAULT_HTTP_HOST)
.setCompressionSupported(true));
server.requestHandler(req -> {
req.response().end(expected);
});
startServer();
client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.bodyHandler(buff -> {
assertEquals(expected, buff);
complete();
});
}).putHeader("Connection", "close")
.exceptionHandler(this::fail)
.end();
await();
}
}

0 comments on commit 1ea29f5

Please sign in to comment.