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

Nicolas Richeton edited comment on HTTPCLIENT-1384 at 8/9/13 7:47 AM:
----------------------------------------------------------------------

Here is the failing unit test for TestProtocolRecommandations :


@Test
        public void testCacheNotInvalidatedOnError() throws Exception {
                final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new 
BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
                final HttpResponse resp1 = HttpTestUtils.make200Response();
                resp1.setHeader("Cache-Control", "max-age=3600");

                backendExpectsAnyRequestAndReturn(resp1);

                final HttpRequestWrapper req1_2 = HttpRequestWrapper
                                .wrap(new BasicHttpRequest("GET", "/", 
HttpVersion.HTTP_1_1));
                // No call to backend expected : served from cache

                final HttpRequestWrapper req2 = HttpRequestWrapper
                                .wrap(new BasicHttpRequest("POST", "/", 
HttpVersion.HTTP_1_1));
                // Returns an error : shoud not invalidate cache
                final HttpResponse resp2 = HttpTestUtils.make500Response();
                backendExpectsAnyRequestAndReturn(resp2);

                final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(new 
BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
                // No call to backend expected : served from cache

                replayMocks();
                final HttpResponse result1 = impl.execute(route, req1, context, 
null);
                final HttpResponse result1_2 = impl.execute(route, req1_2, 
context, null);
                impl.execute(route, req2, context, null);

                // Will fail with NPE if request is sent to backend
                final HttpResponse result3 = impl.execute(route, req3, context, 
null);

                verifyMocks();

                // Ensure comparing results works 
                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result1));

                // Ensure cached before POST w/ error
                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result1_2));

                //Ensure cached after POST w/ error
                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result3));
        }

                
      was (Author: nricheton):
    Here is the failing unit test for TestProtocolRecommandations :


@Test
        public void testCacheNotInvalidatedOnError() throws Exception {
                final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(new 
BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
                final HttpResponse resp1 = HttpTestUtils.make200Response();
                resp1.setHeader("Cache-Control", "max-age=3600");

                backendExpectsAnyRequestAndReturn(resp1);

                final HttpRequestWrapper req1_2 = HttpRequestWrapper
                                .wrap(new BasicHttpRequest("GET", "/", 
HttpVersion.HTTP_1_1));
                // No call to backend expected : served from cache

                final HttpRequestWrapper req2 = HttpRequestWrapper
                                .wrap(new BasicHttpRequest("POST", "/", 
HttpVersion.HTTP_1_1));
                // Returns an error : shoud not invalidate cache
                final HttpResponse resp2 = HttpTestUtils.make500Response();
                backendExpectsAnyRequestAndReturn(resp2);

                final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(new 
BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
                // No call to backend expected : served from cache

                replayMocks();
                final HttpResponse result1 = impl.execute(route, req1, context, 
null);
                final HttpResponse result1_2 = impl.execute(route, req1_2, 
context, null);
                impl.execute(route, req2, context, null);

                // Will fail with NPE is request is sent to backend.
                final HttpResponse result3 = impl.execute(route, req3, context, 
null);

                verifyMocks();

                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result1));
                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result1_2));
                assertTrue(HttpTestUtils.semanticallyTransparent(result1, 
result3));
        }

                  
> Expose CacheInvalidator in CachingHttpClientBuilder
> ---------------------------------------------------
>
>                 Key: HTTPCLIENT-1384
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1384
>             Project: HttpComponents HttpClient
>          Issue Type: Wish
>          Components: HttpCache
>    Affects Versions: 4.2.5, 4.3 Beta2
>            Reporter: Nicolas Richeton
>             Fix For: 4.3 Final
>
>
> There is currently no way to customize the CacheInvalidator. Could it be 
> possible to allow setting a  CacheInvalidator in CachingHttpClientBuilder 
> (eg. CachingHttpClientBuilder#setCacheInvalidator())
> Our use case : 
> - HttpClientCache is used in a Caching Reverse Proxy (shared cache, exposed 
> to public connections)
> - We have to ensure the cache cannot be flush by a random user.  
> - The default CacheInvalidator flushes all variants of an URI when receiving 
> anything other than GET, HEAD (compliant with RFC)
> - It is currently possible for a user to flush the whole cache by sending 
> POST requests of all uri (this may be harmful even only on a home page). 
> While it is not RFC-compliant, we need at least the ability to prevent 
> invalidation in CacheInvalidator#flushInvalidatedCacheEntriesFor and/or 
> control invalidation with custom method  (PURGE) and other criteria (like 
> remote ip)
> The same applies to HttpClientCache 4.2.5: CachingHttpClient which does not 
> allow provide a custom CacheInvalidator
> Would this sound ok for you ? 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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

Reply via email to