ipersite
ipersite

Reputation: 185

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.

Upvotes: 5

Views: 6721

Answers (1)

Ali
Ali

Reputation: 1532

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

Upvotes: 13

Related Questions