#14277·netty

Upstream content encoding misalignment between Http1x and Http2

Author: bjornhusbergCreated Sep 3, 2024Updated Sep 10, 2026
Labelsdefect

Expected behavior

When manually setting the Content-Encoding header and sending an already encoded response the Http1 and Http2 codec should both behave the same, ie they should pass through the already encoded stream and not modify the Content-Encoding header.

Actual behavior

The Http2 codec takes the Content-Encoding header as a hint on how the result should be encoded and then encodes the already encoded stream a second time, resulting in garbage on the client side. Compare the logic in the Http2 codec:

https://github.com/netty/netty/blob/c0fdb8e9f8f256990e902fcfffbbe10754d0f3dd/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java#L366

to the logic in the corresponding Http1 codec:

https://github.com/netty/netty/blob/c0fdb8e9f8f256990e902fcfffbbe10754d0f3dd/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java#L255

Netty version

4.1