HTTPCLIENT-1515: Caching responses to HEAD requests

Fixed API change and removed opt-in parameter

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1637599 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Francois-Xavier Bonnet 2014-11-08 21:47:12 +00:00
parent 2883531e92
commit 0cedb7c8cc
17 changed files with 172 additions and 166 deletions

View File

@ -162,7 +162,6 @@ public class CachingHttpClient implements HttpClient {
private final RequestProtocolCompliance requestCompliance;
private final AsynchronousValidator asynchRevalidator;
private final boolean allowHeadResponseCaching;
private final Log log = LogFactory.getLog(getClass());
@ -180,8 +179,7 @@ public class CachingHttpClient implements HttpClient {
this.responseCache = cache;
this.validityPolicy = new CacheValidityPolicy();
this.responseCachingPolicy = new ResponseCachingPolicy(maxObjectSizeBytes, sharedCache,
config.isNeverCacheHTTP10ResponsesWithQuery(), config.is303CachingEnabled(),
config.isHeadResponseCachingEnabled());
config.isNeverCacheHTTP10ResponsesWithQuery(), config.is303CachingEnabled());
this.responseGenerator = new CachedHttpResponseGenerator(this.validityPolicy);
this.cacheableRequestPolicy = new CacheableRequestPolicy();
this.suitabilityChecker = new CachedResponseSuitabilityChecker(this.validityPolicy, config);
@ -191,7 +189,6 @@ public class CachingHttpClient implements HttpClient {
this.requestCompliance = new RequestProtocolCompliance(config.isWeakETagOnPutDeleteAllowed());
this.asynchRevalidator = makeAsynchronousValidator(config);
this.allowHeadResponseCaching = config.isHeadResponseCachingEnabled();
}
/**
@ -304,7 +301,6 @@ public class CachingHttpClient implements HttpClient {
this.responseCompliance = responseCompliance;
this.requestCompliance = requestCompliance;
this.asynchRevalidator = makeAsynchronousValidator(config);
this.allowHeadResponseCaching = config.isHeadResponseCachingEnabled();
}
private AsynchronousValidator makeAsynchronousValidator(
@ -449,7 +445,7 @@ public class CachingHttpClient implements HttpClient {
flushEntriesInvalidatedByRequest(target, request);
if (!cacheableRequestPolicy.isServableFromCache(request, allowHeadResponseCaching)) {
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
return callBackend(target, request, context);
}

View File

@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
@ -54,6 +55,7 @@ import org.apache.http.util.Args;
public class HttpCacheEntry implements Serializable {
private static final long serialVersionUID = -6300496422359477413L;
private static final String REQUEST_METHOD_HEADER_NAME = "Hc-Request-Method";
private final Date requestDate;
private final Date responseDate;
@ -62,7 +64,6 @@ public class HttpCacheEntry implements Serializable {
private final Resource resource;
private final Map<String,String> variantMap;
private final Date date;
private final String requestMethod;
/**
* Create a new {@link HttpCacheEntry} with variants.
@ -106,7 +107,56 @@ public class HttpCacheEntry implements Serializable {
? new HashMap<String,String>(variantMap)
: null;
this.date = parseDate();
this.requestMethod = requestMethod;
}
/**
* Create a new {@link HttpCacheEntry} with variants.
* @param requestDate
* Date/time when the request was made (Used for age
* calculations)
* @param responseDate
* Date/time that the response came back (Used for age
* calculations)
* @param statusLine
* HTTP status line from origin response
* @param responseHeaders
* Header[] from original HTTP Response
* @param resource representing origin response body
* @param variantMap describing cache entries that are variants
* of this parent entry; this maps a "variant key" (derived
* from the varying request headers) to a "cache key" (where
* in the cache storage the particular variant is located)
*/
public HttpCacheEntry(
final Date requestDate,
final Date responseDate,
final StatusLine statusLine,
final Header[] responseHeaders,
final Resource resource,
final Map<String,String> variantMap) {
this(requestDate, responseDate, statusLine, responseHeaders, resource,
variantMap, null);
}
/**
* Create a new {@link HttpCacheEntry}.
*
* @param requestDate
* Date/time when the request was made (Used for age
* calculations)
* @param responseDate
* Date/time that the response came back (Used for age
* calculations)
* @param statusLine
* HTTP status line from origin response
* @param responseHeaders
* Header[] from original HTTP Response
* @param resource representing origin response body
*/
public HttpCacheEntry(final Date requestDate, final Date responseDate, final StatusLine statusLine,
final Header[] responseHeaders, final Resource resource) {
this(requestDate, responseDate, statusLine, responseHeaders, resource,
new HashMap<String,String>());
}
/**
@ -128,7 +178,7 @@ public class HttpCacheEntry implements Serializable {
public HttpCacheEntry(final Date requestDate, final Date responseDate, final StatusLine statusLine,
final Header[] responseHeaders, final Resource resource, final String requestMethod) {
this(requestDate, responseDate, statusLine, responseHeaders, resource,
new HashMap<String,String>(), requestMethod);
new HashMap<String,String>(),requestMethod);
}
/**
@ -196,7 +246,15 @@ public class HttpCacheEntry implements Serializable {
* Returns all the headers that were on the origin response.
*/
public Header[] getAllHeaders() {
return responseHeaders.getAllHeaders();
final HeaderGroup filteredHeaders = new HeaderGroup();
for (final HeaderIterator iterator = responseHeaders.iterator(); iterator
.hasNext();) {
final Header header = (Header) iterator.next();
if (!REQUEST_METHOD_HEADER_NAME.equals(header.getName())) {
filteredHeaders.addHeader(header);
}
}
return filteredHeaders.getAllHeaders();
}
/**
@ -204,6 +262,9 @@ public class HttpCacheEntry implements Serializable {
* name.
*/
public Header getFirstHeader(final String name) {
if (REQUEST_METHOD_HEADER_NAME.equalsIgnoreCase(name)) {
return null;
}
return responseHeaders.getFirstHeader(name);
}
@ -212,6 +273,9 @@ public class HttpCacheEntry implements Serializable {
* response.
*/
public Header[] getHeaders(final String name) {
if (REQUEST_METHOD_HEADER_NAME.equalsIgnoreCase(name)) {
return new Header[0];
}
return responseHeaders.getHeaders(name);
}
@ -262,7 +326,12 @@ public class HttpCacheEntry implements Serializable {
* @since 4.4
*/
public String getRequestMethod() {
return requestMethod;
final Header requestMethodHeader = responseHeaders
.getFirstHeader(REQUEST_METHOD_HEADER_NAME);
if (requestMethodHeader != null) {
return requestMethodHeader.getValue();
}
return HeaderConstants.GET_METHOD;
}
/**

View File

@ -69,7 +69,6 @@ class BasicHttpCache implements HttpCache {
private final CachedHttpResponseGenerator responseGenerator;
private final HttpCacheInvalidator cacheInvalidator;
private final HttpCacheStorage storage;
private final boolean allowHeadResponseCaching;
private final Log log = LogFactory.getLog(getClass());
@ -86,7 +85,6 @@ class BasicHttpCache implements HttpCache {
this.responseGenerator = new CachedHttpResponseGenerator();
this.storage = storage;
this.cacheInvalidator = cacheInvalidator;
this.allowHeadResponseCaching = config.isHeadResponseCachingEnabled();
}
public BasicHttpCache(
@ -95,7 +93,7 @@ class BasicHttpCache implements HttpCache {
final CacheConfig config,
final CacheKeyGenerator uriExtractor) {
this( resourceFactory, storage, config, uriExtractor,
new CacheInvalidator(uriExtractor, storage, config.isHeadResponseCachingEnabled()));
new CacheInvalidator(uriExtractor, storage));
}
public BasicHttpCache(
@ -256,7 +254,7 @@ class BasicHttpCache implements HttpCache {
src.getAllHeaders(),
resource,
variantMap,
allowHeadResponseCaching ? src.getRequestMethod() : null);
src.getRequestMethod());
}
@Override
@ -268,8 +266,7 @@ class BasicHttpCache implements HttpCache {
stale,
requestSent,
responseReceived,
originResponse,
allowHeadResponseCaching);
originResponse);
storeInCache(target, request, updatedEntry);
return updatedEntry;
}
@ -283,8 +280,7 @@ class BasicHttpCache implements HttpCache {
stale,
requestSent,
responseReceived,
originResponse,
allowHeadResponseCaching);
originResponse);
storage.putEntry(cacheKey, updatedEntry);
return updatedEntry;
}
@ -327,7 +323,7 @@ class BasicHttpCache implements HttpCache {
originResponse.getStatusLine(),
originResponse.getAllHeaders(),
resource,
allowHeadResponseCaching ? request.getRequestLine().getMethod() : null);
request.getRequestLine().getMethod());
storeInCache(host, request, entry);
return responseGenerator.generateResponse(HttpRequestWrapper.wrap(request, host), entry);
} finally {

View File

@ -175,7 +175,6 @@ public class CacheConfig implements Cloneable {
private int asynchronousWorkerIdleLifetimeSecs;
private int revalidationQueueSize;
private boolean neverCacheHTTP10ResponsesWithQuery;
private final boolean allowHeadResponseCaching;
/**
* @deprecated (4.3) use {@link Builder}.
@ -196,7 +195,6 @@ public class CacheConfig implements Cloneable {
this.asynchronousWorkersCore = DEFAULT_ASYNCHRONOUS_WORKERS_CORE;
this.asynchronousWorkerIdleLifetimeSecs = DEFAULT_ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS;
this.revalidationQueueSize = DEFAULT_REVALIDATION_QUEUE_SIZE;
this.allowHeadResponseCaching = false;
}
CacheConfig(
@ -213,8 +211,7 @@ public class CacheConfig implements Cloneable {
final int asynchronousWorkersCore,
final int asynchronousWorkerIdleLifetimeSecs,
final int revalidationQueueSize,
final boolean neverCacheHTTP10ResponsesWithQuery,
final boolean allowHeadResponseCaching) {
final boolean neverCacheHTTP10ResponsesWithQuery) {
super();
this.maxObjectSize = maxObjectSize;
this.maxCacheEntries = maxCacheEntries;
@ -229,7 +226,6 @@ public class CacheConfig implements Cloneable {
this.asynchronousWorkersCore = asynchronousWorkersCore;
this.asynchronousWorkerIdleLifetimeSecs = asynchronousWorkerIdleLifetimeSecs;
this.revalidationQueueSize = revalidationQueueSize;
this.allowHeadResponseCaching = allowHeadResponseCaching;
}
/**
@ -504,14 +500,6 @@ public class CacheConfig implements Cloneable {
return revalidationQueueSize;
}
/**
* Returns whether HEAD response caching is enabled.
* @return {@code true} if it is enabled.
*/
public boolean isHeadResponseCachingEnabled() {
return allowHeadResponseCaching;
}
/**
* Sets the current maximum queue size for background revalidations.
*
@ -545,7 +533,6 @@ public class CacheConfig implements Cloneable {
.setAsynchronousWorkersCore(config.getAsynchronousWorkersCore())
.setAsynchronousWorkerIdleLifetimeSecs(config.getAsynchronousWorkerIdleLifetimeSecs())
.setRevalidationQueueSize(config.getRevalidationQueueSize())
.setAllowHeadResponseCaching(config.isHeadResponseCachingEnabled())
.setNeverCacheHTTP10ResponsesWithQueryString(config.isNeverCacheHTTP10ResponsesWithQuery());
}
@ -566,7 +553,6 @@ public class CacheConfig implements Cloneable {
private int asynchronousWorkerIdleLifetimeSecs;
private int revalidationQueueSize;
private boolean neverCacheHTTP10ResponsesWithQuery;
private boolean allowHeadResponseCaching;
Builder() {
this.maxObjectSize = DEFAULT_MAX_OBJECT_SIZE_BYTES;
@ -582,7 +568,6 @@ public class CacheConfig implements Cloneable {
this.asynchronousWorkersCore = DEFAULT_ASYNCHRONOUS_WORKERS_CORE;
this.asynchronousWorkerIdleLifetimeSecs = DEFAULT_ASYNCHRONOUS_WORKER_IDLE_LIFETIME_SECS;
this.revalidationQueueSize = DEFAULT_REVALIDATION_QUEUE_SIZE;
this.allowHeadResponseCaching = false;
}
/**
@ -722,17 +707,6 @@ public class CacheConfig implements Cloneable {
return this;
}
/**
* Sets whether responses to HEAD requests should be cached or not.
* @param allowHeadResponseCaching should be {@code true} to
* permit HEAD response caching, {@code false} to disable it.
* @param allowHeadResponseCaching
*/
public Builder setAllowHeadResponseCaching(final boolean allowHeadResponseCaching) {
this.allowHeadResponseCaching = allowHeadResponseCaching;
return this;
}
/**
* Sets whether the cache should never cache HTTP 1.0 responses with a query string or not.
* @param neverCacheHTTP10ResponsesWithQuery true to never cache responses with a query
@ -761,8 +735,7 @@ public class CacheConfig implements Cloneable {
asynchronousWorkersCore,
asynchronousWorkerIdleLifetimeSecs,
revalidationQueueSize,
neverCacheHTTP10ResponsesWithQuery,
allowHeadResponseCaching);
neverCacheHTTP10ResponsesWithQuery);
}
}
@ -784,7 +757,6 @@ public class CacheConfig implements Cloneable {
.append(", asynchronousWorkerIdleLifetimeSecs=").append(this.asynchronousWorkerIdleLifetimeSecs)
.append(", revalidationQueueSize=").append(this.revalidationQueueSize)
.append(", neverCacheHTTP10ResponsesWithQuery=").append(this.neverCacheHTTP10ResponsesWithQuery)
.append(", headResponseCachingEnabled=").append(this.allowHeadResponseCaching)
.append("]");
return builder.toString();
}

View File

@ -75,7 +75,6 @@ class CacheEntryUpdater {
* @param requestDate When the request was performed
* @param responseDate When the response was gotten
* @param response The HttpResponse from the backend server call
* @param allowHeadResponseCaching Should the cache entry include the request method
* @return HttpCacheEntry an updated version of the cache entry
* @throws java.io.IOException if something bad happens while trying to read the body from the original entry
*/
@ -84,8 +83,7 @@ class CacheEntryUpdater {
final HttpCacheEntry entry,
final Date requestDate,
final Date responseDate,
final HttpResponse response,
final boolean allowHeadResponseCaching) throws IOException {
final HttpResponse response) throws IOException {
Args.check(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED,
"Response must have 304 status code");
final Header[] mergedHeaders = mergeHeaders(entry, response);
@ -99,7 +97,7 @@ class CacheEntryUpdater {
entry.getStatusLine(),
mergedHeaders,
resource,
allowHeadResponseCaching ? entry.getRequestMethod() : null);
entry.getRequestMethod());
}
protected Header[] mergeHeaders(final HttpCacheEntry entry, final HttpResponse response) {

View File

@ -56,7 +56,6 @@ class CacheInvalidator implements HttpCacheInvalidator {
private final HttpCacheStorage storage;
private final CacheKeyGenerator cacheKeyGenerator;
private final boolean allowHeadResponseCaching;
private final Log log = LogFactory.getLog(getClass());
@ -66,15 +65,12 @@ class CacheInvalidator implements HttpCacheInvalidator {
*
* @param uriExtractor Provides identifiers for the keys to store cache entries
* @param storage the cache to store items away in
* @param allowHeadResponseCaching is HEAD response caching enabled
*/
public CacheInvalidator(
final CacheKeyGenerator uriExtractor,
final HttpCacheStorage storage,
final boolean allowHeadResponseCaching) {
final HttpCacheStorage storage) {
this.cacheKeyGenerator = uriExtractor;
this.storage = storage;
this.allowHeadResponseCaching = allowHeadResponseCaching;
}
/**
@ -117,7 +113,7 @@ class CacheInvalidator implements HttpCacheInvalidator {
}
private boolean shouldInvalidateHeadCacheEntry(final HttpRequest req, final HttpCacheEntry parentCacheEntry) {
return allowHeadResponseCaching && requestIsGet(req) && isAHeadCacheEntry(parentCacheEntry);
return requestIsGet(req) && isAHeadCacheEntry(parentCacheEntry);
}
private boolean requestIsGet(final HttpRequest req) {

View File

@ -49,11 +49,11 @@ class CacheableRequestPolicy {
/**
* Determines if an HttpRequest can be served from the cache.
*
* @param request an HttpRequest
* @param allowHeadResponseCaching is HEAD response caching enabled
* @param request
* an HttpRequest
* @return boolean Is it possible to serve this request from cache
*/
public boolean isServableFromCache(final HttpRequest request, final boolean allowHeadResponseCaching) {
public boolean isServableFromCache(final HttpRequest request) {
final String method = request.getRequestLine().getMethod();
final ProtocolVersion pv = request.getRequestLine().getProtocolVersion();
@ -62,8 +62,8 @@ class CacheableRequestPolicy {
return false;
}
if (!(method.equals(HeaderConstants.GET_METHOD) ||
(allowHeadResponseCaching && method.equals(HeaderConstants.HEAD_METHOD)))) {
if (!(method.equals(HeaderConstants.GET_METHOD) || method
.equals(HeaderConstants.HEAD_METHOD))) {
log.trace("non-GET or non-HEAD request was not serveable from cache");
return false;
}

View File

@ -56,7 +56,6 @@ class CachedResponseSuitabilityChecker {
private final float heuristicCoefficient;
private final long heuristicDefaultLifetime;
private final CacheValidityPolicy validityStrategy;
private final boolean allowHeadResponseCaching;
CachedResponseSuitabilityChecker(final CacheValidityPolicy validityStrategy,
final CacheConfig config) {
@ -66,7 +65,6 @@ class CachedResponseSuitabilityChecker {
this.useHeuristicCaching = config.isHeuristicCachingEnabled();
this.heuristicCoefficient = config.getHeuristicCoefficient();
this.heuristicDefaultLifetime = config.getHeuristicDefaultLifetime();
this.allowHeadResponseCaching = config.isHeadResponseCachingEnabled();
}
CachedResponseSuitabilityChecker(final CacheConfig config) {
@ -168,7 +166,7 @@ class CachedResponseSuitabilityChecker {
return false;
}
if (allowHeadResponseCaching && hasUnsupportedCacheEntryForGet(request, entry)) {
if (hasUnsupportedCacheEntryForGet(request, entry)) {
log.debug("HEAD response caching enabled but the cache entry does not contain a " +
"request method, entity or a 204 response");
return false;

View File

@ -153,8 +153,7 @@ public class CachingExec implements ClientExecChain {
this.requestCompliance = new RequestProtocolCompliance(this.cacheConfig.isWeakETagOnPutDeleteAllowed());
this.responseCachingPolicy = new ResponseCachingPolicy(
this.cacheConfig.getMaxObjectSize(), this.cacheConfig.isSharedCache(),
this.cacheConfig.isNeverCacheHTTP10ResponsesWithQuery(), this.cacheConfig.is303CachingEnabled(),
this.cacheConfig.isHeadResponseCachingEnabled());
this.cacheConfig.isNeverCacheHTTP10ResponsesWithQuery(), this.cacheConfig.is303CachingEnabled());
this.asynchRevalidator = asynchRevalidator;
}
@ -265,7 +264,7 @@ public class CachingExec implements ClientExecChain {
flushEntriesInvalidatedByRequest(context.getTargetHost(), request);
if (!cacheableRequestPolicy.isServableFromCache(request, cacheConfig.isHeadResponseCachingEnabled())) {
if (!cacheableRequestPolicy.isServableFromCache(request)) {
log.debug("Request is not servable from cache");
return callBackend(route, request, context, execAware);
}
@ -424,11 +423,8 @@ public class CachingExec implements ClientExecChain {
}
}
private CloseableHttpResponse generateCachedResponse(
final HttpRequestWrapper request,
final HttpContext context,
final HttpCacheEntry entry,
final Date now) {
private CloseableHttpResponse generateCachedResponse(final HttpRequestWrapper request,
final HttpContext context, final HttpCacheEntry entry, final Date now) {
final CloseableHttpResponse cachedResponse;
if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
|| request.containsHeader(HeaderConstants.IF_MODIFIED_SINCE)) {

View File

@ -140,7 +140,7 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
HttpCacheInvalidator cacheInvalidator = this.httpCacheInvalidator;
if (cacheInvalidator == null) {
cacheInvalidator = new CacheInvalidator(uriExtractor, storageCopy, config.isHeadResponseCachingEnabled());
cacheInvalidator = new CacheInvalidator(uriExtractor, storageCopy);
}
return new CachingExec(mainExec,
@ -162,7 +162,6 @@ public class CachingHttpClientBuilder extends HttpClientBuilder {
return null;
}
@SuppressWarnings("resource")
private SchedulingStrategy createSchedulingStrategy(final CacheConfig config) {
return schedulingStrategy != null ? schedulingStrategy : new ImmediateSchedulingStrategy(config);
}

View File

@ -67,7 +67,6 @@ class ResponseCachingPolicy {
HttpStatus.SC_MOVED_PERMANENTLY,
HttpStatus.SC_GONE));
private final Set<Integer> uncacheableStatuses;
private final boolean allowHeadResponseCaching;
/**
* Define a cache policy that limits the size of things that should be stored
@ -79,13 +78,11 @@ class ResponseCachingPolicy {
* @param neverCache1_0ResponsesWithQueryString true to never cache HTTP 1.0 responses with a query string, false
* to cache if explicit cache headers are found.
* @param allow303Caching if this policy is permitted to cache 303 response
* @param allowHeadResponseCaching is HEAD response caching enabled
*/
public ResponseCachingPolicy(final long maxObjectSizeBytes,
final boolean sharedCache,
final boolean neverCache1_0ResponsesWithQueryString,
final boolean allow303Caching,
final boolean allowHeadResponseCaching) {
final boolean allow303Caching) {
this.maxObjectSizeBytes = maxObjectSizeBytes;
this.sharedCache = sharedCache;
this.neverCache1_0ResponsesWithQueryString = neverCache1_0ResponsesWithQueryString;
@ -96,7 +93,6 @@ class ResponseCachingPolicy {
uncacheableStatuses = new HashSet<Integer>(Arrays.asList(
HttpStatus.SC_PARTIAL_CONTENT, HttpStatus.SC_SEE_OTHER));
}
this.allowHeadResponseCaching = allowHeadResponseCaching;
}
/**
@ -110,7 +106,7 @@ class ResponseCachingPolicy {
boolean cacheable = false;
if (!(HeaderConstants.GET_METHOD.equals(httpMethod) ||
(allowHeadResponseCaching && HeaderConstants.HEAD_METHOD.equals(httpMethod)))) {
HeaderConstants.HEAD_METHOD.equals(httpMethod))) {
log.debug("Response was not cacheable.");
return false;
}

View File

@ -80,7 +80,7 @@ public class TestCacheEntryUpdater {
throws IOException {
entry = HttpTestUtils.makeCacheEntry();
final HttpCacheEntry newEntry = impl.updateCacheEntry(null, entry,
requestDate, responseDate, response, false);
requestDate, responseDate, response);
assertNotSame(newEntry, entry);
}
@ -93,7 +93,7 @@ public class TestCacheEntryUpdater {
response.setHeaders(new Header[]{});
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
new Date(), new Date(), response, false);
new Date(), new Date(), response);
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
@ -117,7 +117,7 @@ public class TestCacheEntryUpdater {
new BasicHeader("Cache-Control", "public")});
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
new Date(), new Date(), response, false);
new Date(), new Date(), response);
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
@ -141,7 +141,7 @@ public class TestCacheEntryUpdater {
new BasicHeader("Cache-Control", "public"),});
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
new Date(), new Date(), response, false);
new Date(), new Date(), response);
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
assertEquals(4, updatedHeaders.length);
@ -163,7 +163,7 @@ public class TestCacheEntryUpdater {
response.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
response.setHeader("ETag", "\"old-etag\"");
final HttpCacheEntry result = impl.updateCacheEntry("A", entry, new Date(),
new Date(), response, false);
new Date(), response);
assertEquals(2, result.getAllHeaders().length);
headersContain(result.getAllHeaders(), "Date", DateUtils.formatDate(oneSecondAgo));
headersContain(result.getAllHeaders(), "ETag", "\"new-etag\"");
@ -174,7 +174,7 @@ public class TestCacheEntryUpdater {
throws IOException {
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
twoSecondsAgo, oneSecondAgo, response, false);
twoSecondsAgo, oneSecondAgo, response);
assertEquals(twoSecondsAgo, updated.getRequestDate());
assertEquals(oneSecondAgo, updated.getResponseDate());
@ -191,7 +191,7 @@ public class TestCacheEntryUpdater {
response.setHeader("ETag", "\"new\"");
response.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
twoSecondsAgo, oneSecondAgo, response, false);
twoSecondsAgo, oneSecondAgo, response);
assertEquals(0, updated.getHeaders("Warning").length);
}
@ -206,7 +206,7 @@ public class TestCacheEntryUpdater {
response.setHeader("ETag", "\"new\"");
response.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
twoSecondsAgo, oneSecondAgo, response, false);
twoSecondsAgo, oneSecondAgo, response);
assertEquals("\"new\"", updated.getFirstHeader("ETag").getValue());
}
@ -221,7 +221,7 @@ public class TestCacheEntryUpdater {
response.setHeader("ETag", "\"new\"");
response.setHeader("Date", "bad-date");
final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
twoSecondsAgo, oneSecondAgo, response, false);
twoSecondsAgo, oneSecondAgo, response);
assertEquals("\"new\"", updated.getFirstHeader("ETag").getValue());
}
@ -233,7 +233,7 @@ public class TestCacheEntryUpdater {
HttpStatus.SC_OK, "OK");
try {
impl.updateCacheEntry("A", entry, new Date(), new Date(),
response, false);
response);
fail("should have thrown exception");
} catch (final IllegalArgumentException expected) {
}

View File

@ -84,7 +84,7 @@ public class TestCacheInvalidator {
request = HttpTestUtils.makeDefaultRequest();
response = HttpTestUtils.make200Response();
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage, false);
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage);
}
private void replayMocks() {
@ -223,7 +223,7 @@ public class TestCacheInvalidator {
@Test
public void testInvalidatesHEADCacheEntryIfSubsequentGETRequestsAreMadeToTheSameURI() throws Exception {
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage, true);
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage);
final String theURI = "http://foo.example.com:80/";
request = new BasicHttpRequest("GET", theURI,HTTP_1_1);
@ -239,7 +239,7 @@ public class TestCacheInvalidator {
@Test
public void testInvalidatesVariantHEADCacheEntriesIfSubsequentGETRequestsAreMadeToTheSameURI() throws Exception {
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage, true);
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage);
final String theURI = "http://foo.example.com:80/";
request = new BasicHttpRequest("GET", theURI,HTTP_1_1);
final String theVariantKey = "{Accept-Encoding=gzip%2Cdeflate&User-Agent=Apache-HttpClient}";
@ -258,7 +258,7 @@ public class TestCacheInvalidator {
}
@Test
public void testDoesNotInvalidateHEADCacheEntryIfHEADResponseCachingIsNotEnabled() throws Exception {
public void testDoesNotInvalidateHEADCacheEntry() throws Exception {
final String theURI = "http://foo.example.com:80/";
request = new BasicHttpRequest("HEAD", theURI,HTTP_1_1);
@ -271,7 +271,7 @@ public class TestCacheInvalidator {
@Test
public void testDoesNotInvalidateHEADCacheEntryIfSubsequentHEADRequestsAreMadeToTheSameURI() throws Exception {
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage, true);
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage);
final String theURI = "http://foo.example.com:80/";
request = new BasicHttpRequest("HEAD", theURI,HTTP_1_1);
@ -284,7 +284,7 @@ public class TestCacheInvalidator {
@Test
public void testDoesNotInvalidateGETCacheEntryIfSubsequentGETRequestsAreMadeToTheSameURI() throws Exception {
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage, true);
impl = new CacheInvalidator(cacheKeyGenerator, mockStorage);
final String theURI = "http://foo.example.com:80/";
request = new BasicHttpRequest("GET", theURI,HTTP_1_1);

View File

@ -35,8 +35,6 @@ public class TestCacheableRequestPolicy {
private CacheableRequestPolicy policy;
private final boolean allowHeadResponseCaching = true;
@Before
public void setUp() throws Exception {
policy = new CacheableRequestPolicy();
@ -46,7 +44,7 @@ public class TestCacheableRequestPolicy {
public void testIsGetServableFromCache() {
final BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
Assert.assertTrue(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertTrue(policy.isServableFromCache(request));
}
@Test
@ -54,19 +52,19 @@ public class TestCacheableRequestPolicy {
BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Cache-Control", "no-cache");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Cache-Control", "no-store");
request.addHeader("Cache-Control", "max-age=20");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Cache-Control", "public");
request.addHeader("Cache-Control", "no-store, max-age=20");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
}
@Test
@ -74,26 +72,26 @@ public class TestCacheableRequestPolicy {
BasicHttpRequest request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Pragma", "no-cache");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("GET", "someUri");
request.addHeader("Pragma", "value1");
request.addHeader("Pragma", "value2");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
}
@Test
public void testIsHeadServableFromCache() {
BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
Assert.assertTrue(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertTrue(policy.isServableFromCache(request));
request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Cache-Control", "public");
request.addHeader("Cache-Control", "max-age=20");
Assert.assertTrue(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertTrue(policy.isServableFromCache(request));
}
@Test
@ -101,19 +99,19 @@ public class TestCacheableRequestPolicy {
BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Cache-Control", "no-cache");
Assert.assertFalse(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Cache-Control", "no-store");
request.addHeader("Cache-Control", "max-age=20");
Assert.assertFalse(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Cache-Control", "public");
request.addHeader("Cache-Control", "no-store, max-age=20");
Assert.assertFalse(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
}
@Test
@ -121,24 +119,24 @@ public class TestCacheableRequestPolicy {
BasicHttpRequest request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Pragma", "no-cache");
Assert.assertFalse(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("HEAD", "someUri");
request.addHeader("Pragma", "value1");
request.addHeader("Pragma", "value2");
Assert.assertFalse(policy.isServableFromCache(request, allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
}
@Test
public void testIsArbitraryMethodServableFromCache() {
BasicHttpRequest request = new BasicHttpRequest("TRACE", "someUri");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
request = new BasicHttpRequest("get", "someUri");
Assert.assertFalse(policy.isServableFromCache(request, !allowHeadResponseCaching));
Assert.assertFalse(policy.isServableFromCache(request));
}

View File

@ -288,8 +288,8 @@ public class TestCachedResponseSuitabilityChecker {
}
@Test
public void testNotSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodOrEntity() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().setAllowHeadResponseCaching(true).build());
public void testNotSuitableForGETIfEntryDoesNotSpecifyARequestMethodOrEntity() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),
@ -301,8 +301,8 @@ public class TestCachedResponseSuitabilityChecker {
}
@Test
public void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodButContainsEntity() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().setAllowHeadResponseCaching(true).build());
public void testSuitableForGETIfEntryDoesNotSpecifyARequestMethodButContainsEntity() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),
@ -315,7 +315,7 @@ public class TestCachedResponseSuitabilityChecker {
@Test
public void testSuitableForGETIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethodButContains204Response() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().setAllowHeadResponseCaching(true).build());
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600")
@ -328,7 +328,7 @@ public class TestCachedResponseSuitabilityChecker {
@Test
public void testSuitableForHEADIfHeadResponseCachingEnabledAndEntryDoesNotSpecifyARequestMethod() {
final HttpRequest headRequest = new BasicHttpRequest("HEAD", "/foo", HttpVersion.HTTP_1_1);
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().setAllowHeadResponseCaching(true).build());
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),

View File

@ -27,7 +27,6 @@
package org.apache.http.impl.client.cache;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
@ -1765,7 +1764,7 @@ public abstract class TestCachingExecChain {
}
protected void requestPolicyAllowsCaching(final boolean allow) {
expect(mockRequestPolicy.isServableFromCache((HttpRequest) anyObject(), anyBoolean())).andReturn(allow);
expect(mockRequestPolicy.isServableFromCache((HttpRequest) anyObject())).andReturn(allow);
}
protected void cacheEntrySuitable(final boolean suitable) {

View File

@ -62,7 +62,7 @@ public class TestResponseCachingPolicy {
sixSecondsAgo = new Date(now.getTime() - 6 * 1000L);
tenSecondsFromNow = new Date(now.getTime() + 10 * 1000L);
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("GET","/",HTTP_1_1);
response = new BasicHttpResponse(
new BasicStatusLine(HTTP_1_1, HttpStatus.SC_OK, ""));
@ -76,18 +76,11 @@ public class TestResponseCachingPolicy {
}
@Test
public void testIsHeadCacheableIfHeadResponseCachingIsEnabled() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
public void testIsHeadCacheable() {
policy = new ResponseCachingPolicy(0, true, false, false);
Assert.assertTrue(policy.isResponseCacheable("HEAD", response));
}
@Test
public void testHeadIsNotCacheableIfHeadResponseCachingIsDisabled() {
request = new BasicHttpRequest("HEAD","/",HTTP_1_1);
policy = new ResponseCachingPolicy(0, true, false, false, false);
Assert.assertFalse(policy.isResponseCacheable("HEAD", response));
}
@Test
public void testResponsesToRequestsWithAuthorizationHeadersAreNotCacheableBySharedCache() {
request = new BasicHttpRequest("GET","/",HTTP_1_1);
@ -97,7 +90,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesToRequestsWithAuthorizationHeadersAreCacheableByNonSharedCache() {
policy = new ResponseCachingPolicy(0, false, false, false, false);
policy = new ResponseCachingPolicy(0, false, false, false);
request = new BasicHttpRequest("GET","/",HTTP_1_1);
request.setHeader("Authorization","Basic dXNlcjpwYXNzd2Q=");
Assert.assertTrue(policy.isResponseCacheable(request,response));
@ -149,7 +142,7 @@ public class TestResponseCachingPolicy {
@Test
public void test206ResponseCodeIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setStatusCode(HttpStatus.SC_PARTIAL_CONTENT);
@ -193,7 +186,7 @@ public class TestResponseCachingPolicy {
@Test
public void testPlain303ResponseCodeIsNotCacheableEvenIf303CachingEnabled() {
policy = new ResponseCachingPolicy(0, true, false, true, false);
policy = new ResponseCachingPolicy(0, true, false, true);
response.setStatusCode(HttpStatus.SC_SEE_OTHER);
response.removeHeaders("Expires");
response.removeHeaders("Cache-Control");
@ -267,7 +260,7 @@ public class TestResponseCachingPolicy {
@Test
public void test200ResponseWithPrivateCacheControlIsCacheableByNonSharedCache() {
policy = new ResponseCachingPolicy(0, false, false, false, false);
policy = new ResponseCachingPolicy(0, false, false, false);
response.setStatusCode(HttpStatus.SC_OK);
response.setHeader("Cache-Control", "private");
Assert.assertTrue(policy.isResponseCacheable("GET", response));
@ -378,7 +371,7 @@ public class TestResponseCachingPolicy {
@Test
public void testIsHeadWithAnyCacheControlCacheable() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
response.addHeader("Cache-Control", "max=10");
Assert.assertTrue(policy.isResponseCacheable("HEAD", response));
@ -426,7 +419,7 @@ public class TestResponseCachingPolicy {
@Test
public void testVaryStarIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -442,7 +435,7 @@ public class TestResponseCachingPolicy {
@Test
public void testIsHeadWithVaryHeaderCacheable() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
response.addHeader("Vary", "Accept-Encoding");
Assert.assertTrue(policy.isResponseCacheable("HEAD", response));
}
@ -457,7 +450,7 @@ public class TestResponseCachingPolicy {
@Test
public void testIsArbitraryMethodCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new HttpOptions("http://foo.example.com/");
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
@ -483,7 +476,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesWithMultipleAgeHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -501,7 +494,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesWithMultipleDateHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -518,7 +511,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesWithMalformedDateHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -535,7 +528,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesWithMultipleExpiresHeadersAreNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -558,7 +551,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponseThatHasTooMuchContentIsNotCacheableUsingSharedPublicCache() {
policy = new ResponseCachingPolicy(0, true, false, false, false);
policy = new ResponseCachingPolicy(0, true, false, false);
request.setHeader("Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
response.setHeader("Cache-Control", "public");
@ -586,14 +579,14 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesToGETWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
policy = new ResponseCachingPolicy(0, true, true, false, false);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("GET", "/foo?s=bar");
Assert.assertFalse(policy.isResponseCacheable(request, response));
}
@Test
public void testResponsesToHEADWithQueryParamsButNoExplicitCachingAreNotCacheableEvenWhen1_0QueryCachingDisabled() {
policy = new ResponseCachingPolicy(0, true, true, false, true);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
Assert.assertFalse(policy.isResponseCacheable(request, response));
}
@ -608,7 +601,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheable() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -617,7 +610,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesToGETWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
policy = new ResponseCachingPolicy(0, true, true, false, false);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("GET", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -626,7 +619,7 @@ public class TestResponseCachingPolicy {
@Test
public void testResponsesToHEADWithQueryParamsAndExplicitCachingAreCacheableEvenWhen1_0QueryCachingDisabled() {
policy = new ResponseCachingPolicy(0, true, true, false, true);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -649,7 +642,7 @@ public class TestResponseCachingPolicy {
@Test
public void getsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
policy = new ResponseCachingPolicy(0, true, true, false, false);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("GET", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
Assert.assertFalse(policy.isResponseCacheable(request, response));
@ -657,7 +650,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersDirectlyFrom1_0OriginsAreNotCacheableEvenWithSetting() {
policy = new ResponseCachingPolicy(0, true, true, false, true);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
Assert.assertFalse(policy.isResponseCacheable(request, response));
@ -674,7 +667,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersDirectlyFrom1_0OriginsAreCacheableWithExpires() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
response.setHeader("Date", DateUtils.formatDate(now));
@ -684,7 +677,7 @@ public class TestResponseCachingPolicy {
@Test
public void getsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, false, false);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("GET", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
response.setHeader("Date", DateUtils.formatDate(now));
@ -694,7 +687,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersDirectlyFrom1_0OriginsCanBeNotCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, false, true);
policy = new ResponseCachingPolicy(0, true, true, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
response.setHeader("Date", DateUtils.formatDate(now));
@ -727,7 +720,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersFrom1_0OriginsViaProxiesAreCacheableWithExpires() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -737,7 +730,7 @@ public class TestResponseCachingPolicy {
@Test
public void getsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, true, false);
policy = new ResponseCachingPolicy(0, true, true, true);
request = new BasicHttpRequest("GET", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -747,7 +740,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersFrom1_0OriginsViaProxiesCanNotBeCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, true, true);
policy = new ResponseCachingPolicy(0, true, true, true);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -766,7 +759,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesAreCacheableWithExpires() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -776,7 +769,7 @@ public class TestResponseCachingPolicy {
@Test
public void getsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, true, false);
policy = new ResponseCachingPolicy(0, true, true, true);
request = new BasicHttpRequest("GET", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -786,7 +779,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersFrom1_0OriginsViaExplicitProxiesCanNotBeCacheableEvenWithExpires() {
policy = new ResponseCachingPolicy(0, true, true, true, true);
policy = new ResponseCachingPolicy(0, true, true, true);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Expires", DateUtils.formatDate(tenSecondsFromNow));
@ -806,7 +799,7 @@ public class TestResponseCachingPolicy {
@Test
public void headsWithQueryParametersFrom1_1OriginsVia1_0ProxiesAreCacheableWithExpires() {
policy = new ResponseCachingPolicy(0, true, false, false, true);
policy = new ResponseCachingPolicy(0, true, false, false);
request = new BasicHttpRequest("HEAD", "/foo?s=bar");
response = new BasicHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "OK");
response.setHeader("Date", DateUtils.formatDate(now));
@ -852,7 +845,7 @@ public class TestResponseCachingPolicy {
public void test303WithExplicitCachingHeadersWhenPermittedByConfig() {
// HTTPbis working group says ok if explicitly indicated by
// response headers
policy = new ResponseCachingPolicy(0, true, false, true, false);
policy = new ResponseCachingPolicy(0, true, false, true);
response.setStatusCode(HttpStatus.SC_SEE_OTHER);
response.setHeader("Date", DateUtils.formatDate(now));
response.setHeader("Cache-Control","max-age=300");