You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/02/07 18:19:13 UTC

[httpcomponents-client] branch 4.5.x updated: Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always use the cached entity's content length, as modern browsers do.

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch 4.5.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/4.5.x by this push:
     new d150f5a  Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always use the cached entity's content length, as modern browsers do.
     new 77cbf6c  Merge branch 'PR-134' into 4.5.x
d150f5a is described below

commit d150f5abae3fc4a51f18a63d2807bf703fa67dd7
Author: Jayson Raymond <jr...@accelerantmobile.com>
AuthorDate: Mon Feb 4 08:57:37 2019 -0800

    Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always use the cached entity's content length, as modern browsers do.
---
 .../http/impl/client/cache/CachedHttpResponseGenerator.java   | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
index 42c01e9..52a50dc 100644
--- a/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
+++ b/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachedHttpResponseGenerator.java
@@ -151,13 +151,10 @@ class CachedHttpResponseGenerator {
         if (transferEncodingIsPresent(response)) {
             return;
         }
-
-        Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
-        if (contentLength == null) {
-            contentLength = new BasicHeader(HTTP.CONTENT_LEN, Long.toString(entity
-                    .getContentLength()));
-            response.setHeader(contentLength);
-        }
+        // Some well known proxies respond with Content-Length=0, when returning 304. For robustness, always
+        // use the cached entity's content length, as modern browsers do.
+        final Header contentLength = new BasicHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
+        response.setHeader(contentLength);
     }
 
     private boolean transferEncodingIsPresent(final HttpResponse response) {