Search code examples
javagziphttpclienthttpresponsecontent-encoding

Java: HttpResponse headers never have "Content-Encoding" but do have "Vary: Accept-Encoding"


I'm using the following example: http://www.devdaily.com/java/jwarehouse/commons-httpclient-4.0.3/httpclient/src/examples/org/apache/http/examples/client/ClientGZipContentCompression.java.shtml

While adding "Accept-Encoding: gzip" to the headers is expected to tell the server you can receive gxip encoding back, it doesn't appear to be working that way. Instead, the servers only respond with "Vary: Accept-Encoding". After a long time of Googling, I couldn't even really find out what "Vary: Accept-Encoding" means. Why aren't the servers responding with "Content-Encoding: gzip" as they should be? Am I missing something?

EDIT: For instance, when checking www.yahoo.com on this website (http://www.gidnetwork.com/tools/gzip-test.php), it pulls in the right header (the content-encoding one). However, when I pull in that website through the Java code, the content-encoding header doesn't show up. Why is that?

Here is the code I'm using to print the headers in Java:

        Header[] h = response.getAllHeaders();
        for (int x = 0; x < h.length; x++)
            System.out.println(h[x]);

Solution

  • Your server is probably not configured to return gzip'ped content.

    EDIT: against http://apache.org/, the code works as described. The paste is at http://pastebin.com/Ajj4XBb1