Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android HttpURLConnection: gzip compression

I can't understand what the documentation says about that.

By default, this implementation of HttpURLConnection requests that servers use gzip compression. Since getContentLength() returns the number of bytes transmitted, you cannot use that method to predict how many bytes can be read from getInputStream(). Instead, read that stream until it is exhausted: when read() returns -1. Gzip compression can be disabled by setting the acceptable encodings in the request header:

urlConnection.setRequestProperty("Accept-Encoding", "identity");

I would like to know if the current implementation actually decompress the stream before returning it (using conn.getInputStream()) or if it simply says that the connection automatically sends the header for gzip encoding and I need to manage with that.

Thanks.

like image 835
ipersite Avatar asked May 08 '13 13:05

ipersite


1 Answers

You dont need to handle this. just use conn.getInputStream()

From this blogpost:

In Gingerbread, we added transparent response compression. HttpURLConnection will automatically add this header to outgoing requests, and handle the corresponding response:

Accept-Encoding: gzip

like image 140
Ali Avatar answered Sep 30 '22 23:09

Ali