Android HttpURLConnection
is doing some magic transparently for you like caching and gzip-handling.
So if you don't set Accept-Encoding: identity
, HUC sets Accept-Encoding: gzip,deflate
. And since nginx is an intelligent nice thing, it might deliver your response gzip
encoded. You didn't tell HUC to give the response as gzipped back to you, but it decompresses that response for you and drops the header since this was misleading.
You can see this as a powerful feature to save bandwidth and radio power consumption without Android programmers having to deal with gzip
or deflate
encoding.
If you just stream the response to your JSON-parser, you will get the uncompressed data in the correct size, though without knowing size in advance.
You could verify what I said by running wireshark
or tcpdump
server-side, or if you have a rooted Android device, there are ways to do this client-side as well.