Skip to content

HttpClientHandler.AutomaticDecompression only decompresses one layer #3742

@erikness

Description

@erikness

Issue description

In HttpClientHandler, you are allowed to set AutomaticDecompression (values are GZip, Deflate, Brotli, None, or a combination of those). The idea is that .NET will automatically decompress HTTP responses for you.

Compression on the HTTP response body is defined by by the "Content-Encoding" header. However, this can have multiple values if the content was compressed multiple times:

Content-Encoding: gzip, br

They are listed in the order that they were applied. That is, this server applied GZip compression to some content, and then applied Brotli compression to that gzipped content.

Both the .NET Framework and .NET Core source code have a peculiar behavior though: if there are multiple specified, it only decompresses the last - or outermost - compression. So in this case, it would decompress the Brotli-encoded content, and then pass along the GZipped content to the user. It would also strip the word "brotli" from the Content-Encoding header, so the user would se it as Content-Encoding: gzip.

Link to .NET Core source code that does this

Link to .NET Framework source code that does this

(I also made a small repro, ask if you need it)

As far as I know this isn't incorrect - .NET is allowed to limit itself to 1 decompression, I guess - but it's not documented anywhere. The right place might be in the docs for HttpClientHandler, or HttpClientHandler.AutomaticDecompression. Though it would also be nice if the .NET team provided a reason why .NET chooses to do this.

Target framework

All versions of Core/Framework/Standard, as far as I know.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions