[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-1953?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16720226#comment-16720226
 ] 

Marco Signorini edited comment on HTTPCLIENT-1953 at 12/13/18 2:40 PM:
-----------------------------------------------------------------------

Sorry for late response.

Chrome browser used for test.

Hit the URL [http://js.omg.neodatagroup.com/omg.js]

The first answer contains the header:

{{Cache-Control: no-cache, must-revalidate}}

The second and following requests contain the {{If-Modified-Since}}; the origin 
server answers with 304 Not modified.

 
However, using the http apache client, all requests are sent to the origin 
server without the {{If-Modified-Since}} and therefore the full content is 
always downloaded.

Attached a java file with sample code.

As a workaround I commented the {{CACHE_CONTROL_NO_CACHE}} check in the 
{{org.apache.http.impl.client.cache.ResponseCachingPolicy}} class

{code:java}
protected boolean isExplicitlyNonCacheable(final HttpResponse response) {
        final Header[] cacheControlHeaders = 
response.getHeaders(HeaderConstants.CACHE_CONTROL);
        for (final Header header : cacheControlHeaders) {
            for (final HeaderElement elem : header.getElements()) {
                if 
(HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName())
                       /* || 
HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName())*/
                        || (sharedCache && 
HeaderConstants.PRIVATE.equals(elem.getName()))) {
                    return true;
                }
            }
        }
        return false;
    }
{code}


Marco



was (Author: m.signorini):
Sorry for late response.

Chrome browser used for test.

Hit the URL [http://js.omg.neodatagroup.com/omg.js]

The first answer contains the header:

{{Cache-Control: no-cache, must-revalidate}}

The second and following requests contain the {{If-Modified-Since}}; the origin 
server answers with 304 Not modified.

 
However, using the http apache client, all requests are sent to the origin 
server without the {{If-Modified-Since}} and therefore the full content is 
always downloaded.

Attached a java file with sample code.

> HTTP Response is not cached with Cache-Control: no-cache header
> ---------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1953
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1953
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpCache
>    Affects Versions: 4.5.6
>            Reporter: Marco Signorini
>            Priority: Major
>         Attachments: WebClientTest.java
>
>
> When the HTTP response contains the Cache-Control: no-cache header, the 
> response should be cached and then validated against the origin server before 
> returning it.
> Now the HTTP response is never cached.
> [https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching]
> [https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to