0

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]);
joshholat
  • 3,371
  • 9
  • 39
  • 48

1 Answers1

1

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

Femi
  • 64,273
  • 8
  • 118
  • 148
  • I'm just using HttpGet to try various different web addresses. – joshholat Jun 01 '11 at 21:52
  • Ah. Show some code. And see http://stackoverflow.com/questions/1573391/android-http-communication-should-use-accept-encoding-gzip – Femi Jun 01 '11 at 22:00
  • The URL I included in the post has the code I'm trying to get working. It's out of the box example code. Also, I'm already doing what the link you posted suggested. The problem is servers don't respond with any headers that contain "gzip". – joshholat Jun 01 '11 at 22:07
  • Ah. Well, perhaps you changed something: I copied/pasted that code into a new text file, compiled it against httpclient-4.0.3.jar and httpcore-4.0.1.jar and ran it and it fetched a gzipped response. See http://pastebin.com/Ajj4XBb1 for the exact file I compiled: all I did was change the package name and class name to test, and I ran it at a windows command line like so: `java -cp .;httpclient-4.0.3.jar;httpcore-4.0.1.jar;commons-logging-1.0.3.jar test` – Femi Jun 01 '11 at 22:22
  • When you say it fetched a gzipped response, do you mean it output the uncompressed size? How did you confirm that it was in fact sending gzipped data? Note: Also check out my edit in the original question. – joshholat Jun 01 '11 at 22:58
  • It printed out the header (see line 78) and the content length matched the value returned by `wget`. You can see the value with wget using `wget -S --header="Accept-Encoding: gzip" http://apache.org/`. – Femi Jun 01 '11 at 23:05
  • I just tried this at home on my own wifi vs at work and it worked. It must be something with being behind a proxy at work or something. Does that make sense? – joshholat Jun 02 '11 at 03:40
  • 1
    Entirely possible: there are many many many badly built proxies that easily screw up headers. – Femi Jun 02 '11 at 03:42