anaisbetts / ModernHttpClient

HttpClient implementations that use platform-native HTTP clients for :rocket:
MIT License
662 stars 263 forks source link

On Android gzip is not automatic decompression #222

Open lufo88 opened 7 years ago

lufo88 commented 7 years ago

Hi,

I use ModernHttpClient in a app. The app is in two version, iOS and Android. I can use the gzip header in the request (the server support it) In iOS modernhttpclient has no problem, but in Android the response is still compressed.

My code

using (var client = new HttpClient(new NativeMessageHandler())) {
client.DefaultRequestHeaders.Add ("Accept-Encoding", "gzip");
//other code
var result = response.Content.ReadAsStringAsync().Result; //still compressed, _only_ in Android, iOS works fine
}

I try to add AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate to the handler but nothing change

Any idea?

Cheesebaron commented 7 years ago

Try remove the header and just set AutomaticDecompression. If you inspect the headers incoming on the server it should do compression/decompression transparently.

ghost commented 7 years ago

Try remove the header and just set AutomaticDecompression. If you inspect the headers incoming on the server it should do compression/decompression transparently.

I also try this way, but in the header of the request there is not the header of gzip (I check it in the code of the app).

ghost commented 7 years ago

I also check the response with the AutomaticDecompression set. The server return me content-lenght of the response if gzip is enable and another header:
Content-encoding "gzip"

If I set only AutomaticDecompression the response have not these headers.

This problem is only on Android, so maybe is a problem of okhttp.