What type of response listener should we use to handle gzip responses with Android Volley?
If a String listener is used, the answer seems to lose its encoding.
How do you handle gzip responses with Volley?
BASIC IMAGE: HttpUrlConnection automatically adds the gzip header to requests, and if the response is gzipped, it will easily decode it and present you with the answer. All gzip stuff happens behind the scenes and you donβt need to do what I wrote as an answer to this question. See the documentation here http://developer.android.com/reference/java/net/HttpURLConnection.html
In fact, the answer I posted MUST NOT be used because gzip decoding is extremely slow and should be left to handle the HttpUrlConnection.
Here is the exact part from the documentation:
By default, this HttpURLConnection implementation requires that servers use gzip compression. Since getContentLength () returns the number of bytes transferred, you cannot use this method to predict how many bytes can be read from getInputStream (). Instead, read that thread until it is exhausted: when read () returns -1. Gzip compression can be disabled by setting acceptable encodings in the request header:
urlConnection.setRequestProperty("Accept-Encoding", "identity");
source share