@Test public void testOrderOfMultipleWWWAuthenticateHeadersIsPreservedOnResponses() throws Exception { originResponse.addHeader("WWW-Authenticate", "x-challenge-1"); originResponse.addHeader("WWW-Authenticate", "x-challenge-2"); testOrderOfMultipleHeadersIsPreservedOnResponses("WWW-Authenticate"); }
@Test public void testOrderOfMultipleAllowHeadersIsPreservedOnResponses() throws Exception { originResponse = new BasicClassicHttpResponse(405, "Method Not Allowed"); originResponse.addHeader("Allow", "HEAD"); originResponse.addHeader("Allow", "DELETE"); testOrderOfMultipleHeadersIsPreservedOnResponses("Allow"); }
@Test public void testDoesNotAddContentRangeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderToOriginResponse("Content-Range"); }
@Test public void testDoesNotAddContentEncodingHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderOnCacheHit("Content-Encoding"); }
@Test public void testDoesNotAddContentRangeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderOnCacheHit("Content-Range"); }
@Test public void testDoesNotAddContentEncodingHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderToOriginResponse("Content-Encoding"); }
@Test public void testDoesNotAddContentTypeHeaderToCachedResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderOnCacheHit("Content-Type"); }
@Test public void testDoesNotAddContentTypeHeaderToOriginResponseWithNoTransformIfNotPresent() throws Exception { originResponse.addHeader("Cache-Control","no-transform"); testDoesNotAddHeaderToOriginResponse("Content-Type"); }
@Test public void testRemovesWarningHeaderIfAllWarnValuesAreBadlyDated() throws Exception { final Date now = new Date(); final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); originResponse.setHeader("Date", DateUtils.formatDate(now)); originResponse.addHeader("Warning", "110 wilma \"stale\" \"" + DateUtils.formatDate(tenSecondsAgo) + "\""); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); final Header[] warningHeaders = result.getHeaders("Warning"); Assert.assertTrue(warningHeaders == null || warningHeaders.length == 0); }
@Test public void testResponsesToOPTIONSAreNotCacheable() throws Exception { emptyMockCacheExpectsNoPuts(); request = new BasicClassicHttpRequest("OPTIONS", "/"); originResponse.addHeader("Cache-Control", "max-age=3600"); EasyMock.expect( mockExecChain.proceed( EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class))).andReturn(originResponse); replayMocks(); execute(request); verifyMocks(); }
@Test public void testForwardsExistingWarningHeadersOnResponseThatArrivesStale() throws Exception { originResponse.setHeader("Date", DateUtils.formatDate(tenSecondsAgo)); originResponse.setHeader("Cache-Control","public, max-age=5"); originResponse.setHeader("ETag","\"etag\""); originResponse.addHeader("Age","10"); final String warning = "110 fred \"Response is stale\""; originResponse.addHeader("Warning",warning); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); assertEquals(warning, result.getFirstHeader("Warning").getValue()); }
private void testDoesNotModifyHeaderFromOriginResponseWithNoTransform(final String header, final String value) throws Exception { originResponse.addHeader("Cache-Control","no-transform"); originResponse.setHeader(header, value); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertEquals(value, result.getFirstHeader(header).getValue()); }
@Test public void testRetainsWarningHeadersReceivedFromUpstream() throws Exception { originResponse.removeHeaders("Warning"); final String warning = "199 fred \"misc\""; originResponse.addHeader("Warning", warning); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); final ClassicHttpResponse result = execute(request); verifyMocks(); Assert.assertEquals(warning, result.getFirstHeader("Warning").getValue()); }
private void testDoesNotAddHeaderOnCacheHit(final String header) throws Exception { final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/"); final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/"); originResponse.addHeader("Cache-Control", "max-age=3600"); originResponse.removeHeaders(header); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); execute(req1); final ClassicHttpResponse result = execute(req2); verifyMocks(); Assert.assertNull(result.getFirstHeader(header)); }
private void testDoesNotModifyHeaderOnCachedResponseWithNoTransform(final String header, final String value) throws Exception { final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/"); final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/"); originResponse.addHeader("Cache-Control","max-age=3600, no-transform"); originResponse.setHeader(header, value); backendExpectsAnyRequest().andReturn(originResponse); replayMocks(); execute(req1); final ClassicHttpResponse result = execute(req2); verifyMocks(); Assert.assertEquals(value, result.getFirstHeader(header).getValue()); }