[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r1006348 - in
From:       olegk () apache ! org
Date:       2010-10-10 19:59:39
Message-ID: 20101010195940.0887C2388993 () eris ! apache ! org
[Download RAW message or body]

Author: olegk
Date: Sun Oct 10 19:59:39 2010
New Revision: 1006348

URL: http://svn.apache.org/viewvc?rev=1006348&view=rev
Log:
HTTPCLIENT-1009: content-type / content-encoding headers on cache response entities
Contributed by Felix Berger <bflat1 at gmx.net>

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
  httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java


Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java
                
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src \
/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java?rev=1006348&r1=1006347&r2=1006348&view=diff
 ==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java \
                (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/SizeLimitedResponseReader.java \
Sun Oct 10 19:59:39 2010 @@ -117,7 +117,13 @@ class SizeLimitedResponseReader {
         ensureConsumed();
         HttpResponse reconstructed = new \
BasicHttpResponse(response.getStatusLine());  \
                reconstructed.setHeaders(response.getAllHeaders());
-        reconstructed.setEntity(new CombinedEntity(resource, instream));
+        CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
+        HttpEntity entity = response.getEntity();
+        if (entity != null) {
+            combinedEntity.setContentType(entity.getContentType());
+            combinedEntity.setContentEncoding(entity.getContentEncoding());
+        }
+        reconstructed.setEntity(combinedEntity);
         return reconstructed;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java
                
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src \
/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java?rev=1006348&r1=1006347&r2=1006348&view=diff
 ==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java \
                (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestSizeLimitedResponseReader.java \
Sun Oct 10 19:59:39 2010 @@ -26,12 +26,14 @@
  */
 package org.apache.http.impl.client.cache;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.util.EntityUtils;
 import org.junit.Assert;
@@ -114,6 +116,27 @@ public class TestSizeLimitedResponseRead
     }
 
     @Test
+    public void testTooLargeEntityHasOriginalContentTypes() throws Exception {
+        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, \
HttpStatus.SC_OK, "OK"); +        StringEntity entity = new StringEntity("large \
entity content", "text/plain", "utf-8"); +        response.setEntity(entity);
+
+        impl = new SizeLimitedResponseReader(new HeapResourceFactory(), MAX_SIZE, \
request, response); +
+        impl.readResponse();
+        boolean tooLarge = impl.isLimitReached();
+        HttpResponse result = impl.getReconstructedResponse();
+        HttpEntity reconstructedEntity = result.getEntity();
+        Assert.assertEquals(entity.getContentEncoding(), \
reconstructedEntity.getContentEncoding()); +        \
Assert.assertEquals(entity.getContentType(), reconstructedEntity.getContentType()); +
+        String content = EntityUtils.toString(reconstructedEntity);
+
+        Assert.assertTrue(tooLarge);
+        Assert.assertEquals("large entity content", content);
+    }
+
+    @Test
     public void testResponseCopiesAllOriginalHeaders() throws Exception {
         byte[] buf = new byte[] { 1, 2, 3 };
         HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, \
HttpStatus.SC_OK, "OK");


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic