aiohttp decompresses 'Content-Encoding: gzip' responses #4462
Description
Long story (not so) short
aiohttp automatically decompresses responses with a Content-Encoding header. I believe this is incorrect – while decompression may of course be useful, it should not be on by default.
The Content-Encoding header is similar to the Transfer-Encoding one, and the two are often confused. The difference is that TE is about the data transfer, i.e. the encoding for a particular connection and client, whereas CE is about the data itself. CE exists to allow specifying this encoding without losing the MIME type of the actual data.
As an example, an ideal response for a .tar.gz file download would have a Content-Type: application/x-tar header and a Content-Encoding: gzip one (rather than e.g. Content-Type: application/x-gzip without Content-Encoding). When downloading such a file, one would still expect to get the .tar.gz file, not an uncompressed .tar. This is why I think that aiohttp should not automatically decompress on a Content-Encoding header.
Steps to reproduce
Make a request for a file that has been gzipped, and read from the ClientResponse object (e.g. to write it to a file).
Expected behaviour
Get the gzipped file.
Actual behaviour
Returns the decompressed file.
Your environment
All versions are affected (oldest checked: 2.3.10, but presumably much older than that).
Additional notes
curl also used to have this bug in their HTTP/2 implementation. I haven't searched in detail whether it existed in the HTTP/1.1 one as well, but current versions do not decompress such responses.