Android HttpURLConnection does some magic transparently for you, like caching and gzip processing.
So, if you do not install Accept-Encoding: identity , HUC sets Accept-Encoding: gzip,deflate . And since nginx is a smart, nice thing, it can pass your gzip response in encoding. You did not tell the HUC to give the answer as gzipped for you, but it unpacks that answer for you and resets the header as it is misleading.
You can see this as a powerful feature to save bandwidth and power consumption without Android programs dealing with gzip or deflate encoding.
If you simply pass the response to your JSON parser, you will receive uncompressed data in the correct size, although you do not know the size in advance.
You can verify what I said by doing wireshark or tcpdump on the server side, or if you have an Android root device, there are ways to do this on the client side as well.
source share