OSDN Git Service

Don't leave the Content-Encoding header around after transparent gzip.
authorJesse Wilson <jessewilson@google.com>
Fri, 17 Sep 2010 17:41:33 +0000 (10:41 -0700)
committerJesse Wilson <jessewilson@google.com>
Fri, 17 Sep 2010 17:41:33 +0000 (10:41 -0700)
Otherwise clients may be tempted to double-decompress.
http://b/issue?id=3009828

Change-Id: I4832da1c2aff9bad8d452ffc4a0f98ee27d44f49

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
luni/src/test/java/libcore/java/net/URLConnectionTest.java

index 4486110..cc62b02 100644 (file)
@@ -518,6 +518,11 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
     private InputStream initContentStream() throws IOException {
         InputStream transferStream = getTransferStream();
         if (transparentGzip && "gzip".equalsIgnoreCase(responseHeader.get("Content-Encoding"))) {
+            /*
+             * If the response was transparently gzipped, remove the gzip header
+             * so clients don't double decompress. http://b/3009828
+             */
+            responseHeader.removeAll("Content-Encoding");
             responseBodyIn = new GZIPInputStream(transferStream);
         } else {
             responseBodyIn = transferStream;
index 5894df6..ef857c8 100644 (file)
@@ -394,7 +394,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
         assertEquals(1, server.takeRequest().getSequenceNumber());
     }
 
-    public void testConnectViaHttpsReusingConnectionsDiffeerentFactories()
+    public void testConnectViaHttpsReusingConnectionsDifferentFactories()
             throws IOException, InterruptedException {
         TestSSLContext testSSLContext = TestSSLContext.create();
 
@@ -797,6 +797,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
 
         URLConnection connection = server.getUrl("/").openConnection();
         assertEquals("ABCABCABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+        assertNull(connection.getContentEncoding());
 
         RecordedRequest request = server.takeRequest();
         assertContains(request.getHeaders(), "Accept-Encoding: gzip");