protected void testUnsafeMethodInvalidatesCacheForRelativeUriInContentLocationHeader( final ClassicHttpRequest unsafeReq) throws Exception { unsafeReq.setHeader("Content-Location","/content"); testUnsafeMethodInvalidatesCacheForHeaderUri(unsafeReq); }
@Test public void testDoesNotModifyAuthorizationOnRequests() throws Exception { request.setHeader("Authorization", "Basic dXNlcjpwYXNzd2Q="); testDoesNotModifyHeaderOnRequests("Authorization"); }
@Test public void testDoesNotModifyFromOnRequests() throws Exception { request.setHeader("From", "foo@example.com"); testDoesNotModifyHeaderOnRequests("From"); }
@Test public void testDoesNotModifyUserAgentOnRequests() throws Exception { request.setHeader("User-Agent", "MyClient/1.0"); testDoesNotModifyHeaderOnRequests("User-Agent"); }
@Test public void testDoesNotModifyContentMD5OnRequests() throws Exception { final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/"); post.setEntity(HttpTestUtils.makeBody(128)); post.setHeader("Content-Length","128"); post.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ=="); request = post; testDoesNotModifyHeaderOnRequests("Content-MD5"); }
@Test public void testDoesNotModifyContentRangeOnRequests() throws Exception { final ClassicHttpRequest put = new BasicClassicHttpRequest("PUT", "/"); put.setEntity(HttpTestUtils.makeBody(128)); put.setHeader("Content-Length","128"); put.setHeader("Content-Range","bytes 0-127/256"); request = put; testDoesNotModifyHeaderOnRequests("Content-Range"); }
@Test public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFirstHandOneWithPragma() throws Exception { final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/"); req.setHeader("Pragma","no-cache"); testDoesNotReturnStaleResponseOnError(req); }
@Test public void testDoesNotReturnStaleResponseIfClientExplicitlySpecifiesLargerMaxAge() throws Exception { final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/"); req.setHeader("Cache-Control","max-age=20"); testDoesNotReturnStaleResponseOnError(req); }
@Test public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMinFresh() throws Exception { final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/"); req.setHeader("Cache-Control","min-fresh=2"); testDoesNotReturnStaleResponseOnError(req); }
@Test public void testDoesNotModifyIfUnmodifiedSinceOnRequests() throws Exception { request = new BasicClassicHttpRequest("DELETE", "/"); request.setHeader("If-Unmodified-Since", DateUtils.formatDate(new Date())); testDoesNotModifyHeaderOnRequests("If-Unmodified-Since"); }
@Test public void testDoesNotModifyVaryOnResponses() throws Exception { request.setHeader("Accept-Encoding","identity"); originResponse.setHeader("Vary", "Accept-Encoding"); testDoesNotModifyHeaderOnResponses("Vary"); }
@Test public void testCacheIsNotUsedWhenRespondingToRequestWithPragmaNoCache() throws Exception { final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/"); req.setHeader("Pragma","no-cache"); testCacheIsNotUsedWhenRespondingToRequest(req); }
@Test public void testDoesNotReturnStaleResponseIfClientExplicitlyRequestsFreshWithMaxAge() throws Exception { final ClassicHttpRequest req = new BasicClassicHttpRequest("GET", "/"); req.setHeader("Cache-Control","max-age=0"); testDoesNotReturnStaleResponseOnError(req); }
@Test public void testDoesNotModifyContentLengthOnRequests() throws Exception { final ClassicHttpRequest post = new BasicClassicHttpRequest("POST", "/"); post.setEntity(HttpTestUtils.makeBody(128)); post.setHeader("Content-Length","128"); request = post; testDoesNotModifyHeaderOnRequests("Content-Length"); }
@Test public void testDoesNotForwardOPTIONSWhenMaxForwardsIsZeroOnAbsoluteURIRequest() throws Exception { request = new BasicClassicHttpRequest("OPTIONS", "*"); request.setHeader("Max-Forwards", "0"); replayMocks(); execute(request); verifyMocks(); }
@Test public void testDoesNotModifyContentRangeOnResponses() throws Exception { request.setHeader("Range","bytes=0-128"); originResponse.setCode(HttpStatus.SC_PARTIAL_CONTENT); originResponse.setReasonPhrase("Partial Content"); originResponse.setEntity(HttpTestUtils.makeBody(128)); originResponse.setHeader("Content-Range","bytes 0-127/256"); testDoesNotModifyHeaderOnResponses("Content-Range"); }
@Test public void testSetsModuleGeneratedResponseContextForCacheOptionsResponse() throws Exception { impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final ClassicHttpRequest req = new BasicClassicHttpRequest("OPTIONS", "*"); req.setHeader("Max-Forwards", "0"); execute(req); Assert.assertEquals(CacheResponseStatus.CACHE_MODULE_RESPONSE, context.getCacheResponseStatus()); }
@Test public void testSetsCacheMissContextIfRequestNotServableFromCache() throws Exception { impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final ClassicHttpRequest req = new HttpGet("http://foo.example.com/"); req.setHeader("Cache-Control", "no-cache"); final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content"); backendExpectsAnyRequestAndReturn(resp); replayMocks(); execute(req); verifyMocks(); Assert.assertEquals(CacheResponseStatus.CACHE_MISS, context.getCacheResponseStatus()); }
@Test public void testSetsViaHeaderOnResponseIfRequestNotServableFromCache() throws Exception { impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final ClassicHttpRequest req = new HttpGet("http://foo.example.com/"); req.setHeader("Cache-Control", "no-cache"); final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_NO_CONTENT, "No Content"); backendExpectsAnyRequestAndReturn(resp); replayMocks(); final ClassicHttpResponse result = execute(req); verifyMocks(); Assert.assertNotNull(result.getFirstHeader("Via")); }