Hello,

English is not my native language; please excuse typing errors.
I use HttpClient 4.5.12.

I found that despite a cache hit, the CachingHttpClient returns null, if the 
content-length header was missing in the original response. It worked fine 
after forcing the server to add the content-length header, but this isn't 
possible in case of chunked transfer encoding.
I looked into the source code and found, that the content-length header of a 
subsequent response is merged into the cache entry's response headers, if the 
content-length header was missing in the original response. In case of a 304 
content-length=0 is merged into the cache entry and this causes returning null 
instead of the cached entity.
In CachedHttpResponseGenerator I found the following method:

    private void addMissingContentLengthHeader(final HttpResponse response, 
final HttpEntity entity) {
        if (transferEncodingIsPresent(response)) {
            return;
        }
        // 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);
    }

Obviously, this method adds a missing content length header, but not in case of 
chunked transfer encoding. How can I solve this?

Thanks in advance and best regards,
Dirk Henselin

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to