bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
670 stars 133 forks source link

DisableCompression is ignored in http2 requests #39

Closed jsnjack closed 1 year ago

jsnjack commented 1 year ago

When retrieving a resource via http2, fhttp library always decompresses the body, even if DisableCompression is set to true. According to the option description this should not happen:

    // DisableCompression, if true, prevents the Transport from
    // requesting compression with an "Accept-Encoding: gzip"
    // request header when the Request contains no existing
    // Accept-Encoding value. If the Transport requests gzip on
    // its own and gets a gzipped response, it's transparently
    // decoded in the Response.Body. However, if the user
    // explicitly requested gzip it is not automatically
    // uncompressed.

I looked into parts which read body in http1 and http2 and compared them. http1 has addedGzip flag which is checked before calling DecompressBody function (https://github.com/bogdanfinn/fhttp/blob/959a7f72d1ca6d6319e1ed82a26eea431658d3b3/transport.go#L2190). In http2 we have requestedGzip flag, which acts in similar way. However, requestedGzip is not checked (https://github.com/bogdanfinn/fhttp/blob/master/http2/transport.go#L2259).

The following change seem to solve the issue https://github.com/bogdanfinn/fhttp/commit/8237b3b211da3c741ce9d3fe20a5187e5bb7a694

bogdanfinn commented 1 year ago

@jsnjack thank you for supplying the fix for that. will include that in the next release and i think about adding an option to the tlsclient itself to be able to set DisableCompression to either true or false.

jsnjack commented 1 year ago

Thanks!

By the way, tlsclient already has this option. It can be set via TransportOptions

bogdanfinn commented 1 year ago

https://github.com/bogdanfinn/tls-client/releases/tag/v1.3.10