Skip to content

Commit cdca04b

Browse files
committed
Work around HTTP/2 decompression padding issue.
Motivation: It seems that Netty HTTP/2 decompression accounts for padding twice, failing the decompression of a response when padding is not zero. Changes: When processing a compressed entity, set padding to zero and refund the padding to the original flow controller immediately.
1 parent 985aa53 commit cdca04b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

vertx-core/src/main/java/io/vertx/core/http/impl/VertxHttp2ConnectionHandler.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class VertxHttp2ConnectionHandler<C extends Http2ConnectionBase> extends Http2Co
4545
private final boolean useDecompressor;
4646
private final Http2Settings initialSettings;
4747
public boolean upgraded;
48+
private final Http2LocalFlowController defaultController;
4849

4950
public VertxHttp2ConnectionHandler(
5051
Function<VertxHttp2ConnectionHandler<C>, C> connectionFactory,
@@ -53,6 +54,7 @@ public VertxHttp2ConnectionHandler(
5354
Http2ConnectionEncoder encoder,
5455
Http2Settings initialSettings) {
5556
super(decoder, encoder, initialSettings);
57+
this.defaultController = decoder.flowController();
5658
this.connectionFactory = connectionFactory;
5759
this.useDecompressor = useDecompressor;
5860
this.initialSettings = initialSettings;
@@ -386,7 +388,19 @@ public void onSettingsAckRead(ChannelHandlerContext ctx) throws Http2Exception {
386388
@Override
387389
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) throws Http2Exception {
388390
if (useDecompressor) {
389-
decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection));
391+
decoder().frameListener(new DelegatingDecompressorFrameListener(decoder().connection(), connection) {
392+
@Override
393+
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
394+
// Work around padded decompression
395+
// this should be removed when response decompression is fixed
396+
if (padding > 0) {
397+
VertxHttp2Stream<?> stream = connection.stream(streamId);
398+
defaultController.consumeBytes(stream.stream, padding);
399+
padding = 0;
400+
}
401+
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
402+
}
403+
});
390404
} else {
391405
decoder().frameListener(connection);
392406
}

0 commit comments

Comments
 (0)