HTTPCLIENT-1116: ResponseCachingPolicy uses integers for sizes
Contributed by Greg Bowyer <gbowyer at fastmail.co.uk > git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1172302 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e5ea32b76d
commit
72a41afd5e
|
@ -1,5 +1,8 @@
|
|||
Changes since 4.1.2
|
||||
|
||||
* [HTTPCLIENT-1116] ResponseCachingPolicy uses integers for sizes
|
||||
Contributed by Greg Bowyer <gbowyer at fastmail.co.uk >
|
||||
|
||||
* [HTTPCLIENT-1123] Support for pluggable DNS resolvers.
|
||||
Contributed by Alin Vasile <alinachegalati at yahoo dot com>
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ class BasicHttpCache implements HttpCache {
|
|||
|
||||
private final CacheKeyGenerator uriExtractor;
|
||||
private final ResourceFactory resourceFactory;
|
||||
private final int maxObjectSizeBytes;
|
||||
private final long maxObjectSizeBytes;
|
||||
private final CacheEntryUpdater cacheEntryUpdater;
|
||||
private final CachedHttpResponseGenerator responseGenerator;
|
||||
private final CacheInvalidator cacheInvalidator;
|
||||
|
@ -64,7 +64,7 @@ class BasicHttpCache implements HttpCache {
|
|||
this.resourceFactory = resourceFactory;
|
||||
this.uriExtractor = new CacheKeyGenerator();
|
||||
this.cacheEntryUpdater = new CacheEntryUpdater(resourceFactory);
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSize();
|
||||
this.responseGenerator = new CachedHttpResponseGenerator();
|
||||
this.storage = storage;
|
||||
this.cacheInvalidator = new CacheInvalidator(this.uriExtractor, this.storage);
|
||||
|
|
|
@ -131,7 +131,7 @@ public class CacheConfig {
|
|||
*/
|
||||
public static final int DEFAULT_REVALIDATION_QUEUE_SIZE = 100;
|
||||
|
||||
private int maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
|
||||
private long maxObjectSize = DEFAULT_MAX_OBJECT_SIZE_BYTES;
|
||||
private int maxCacheEntries = DEFAULT_MAX_CACHE_ENTRIES;
|
||||
private int maxUpdateRetries = DEFAULT_MAX_UPDATE_RETRIES;
|
||||
private boolean heuristicCachingEnabled = false;
|
||||
|
@ -146,17 +146,47 @@ public class CacheConfig {
|
|||
/**
|
||||
* Returns the current maximum response body size that will be cached.
|
||||
* @return size in bytes
|
||||
*
|
||||
* @deprecated use {@link #getMaxObjectSize()}
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxObjectSizeBytes() {
|
||||
return maxObjectSizeBytes;
|
||||
return maxObjectSize > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) maxObjectSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the maximum response body size that will be eligible for caching.
|
||||
* @param maxObjectSizeBytes size in bytes
|
||||
*
|
||||
* @deprecated use {@link #setMaxObjectSize(long)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setMaxObjectSizeBytes(int maxObjectSizeBytes) {
|
||||
this.maxObjectSizeBytes = maxObjectSizeBytes;
|
||||
if (maxObjectSizeBytes > Integer.MAX_VALUE) {
|
||||
this.maxObjectSize = Integer.MAX_VALUE;
|
||||
} else {
|
||||
this.maxObjectSize = maxObjectSizeBytes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current maximum response body size that will be cached.
|
||||
* @return size in bytes
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public long getMaxObjectSize() {
|
||||
return maxObjectSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the maximum response body size that will be eligible for caching.
|
||||
* @param maxObjectSize size in bytes
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setMaxObjectSize(long maxObjectSize) {
|
||||
this.maxObjectSize = maxObjectSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,7 +130,7 @@ public class CachingHttpClient implements HttpClient {
|
|||
|
||||
private final ConditionalRequestBuilder conditionalRequestBuilder;
|
||||
|
||||
private final int maxObjectSizeBytes;
|
||||
private final long maxObjectSizeBytes;
|
||||
private final boolean sharedCache;
|
||||
|
||||
private final ResponseProtocolCompliance responseCompliance;
|
||||
|
@ -154,7 +154,7 @@ public class CachingHttpClient implements HttpClient {
|
|||
if (config == null) {
|
||||
throw new IllegalArgumentException("CacheConfig may not be null");
|
||||
}
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSize();
|
||||
this.sharedCache = config.isSharedCache();
|
||||
this.backend = client;
|
||||
this.responseCache = cache;
|
||||
|
@ -268,7 +268,7 @@ public class CachingHttpClient implements HttpClient {
|
|||
ResponseProtocolCompliance responseCompliance,
|
||||
RequestProtocolCompliance requestCompliance) {
|
||||
CacheConfig config = new CacheConfig();
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSizeBytes();
|
||||
this.maxObjectSizeBytes = config.getMaxObjectSize();
|
||||
this.sharedCache = config.isSharedCache();
|
||||
this.backend = backend;
|
||||
this.validityPolicy = validityPolicy;
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.apache.http.protocol.HTTP;
|
|||
@Immutable
|
||||
class ResponseCachingPolicy {
|
||||
|
||||
private final int maxObjectSizeBytes;
|
||||
private final long maxObjectSizeBytes;
|
||||
private final boolean sharedCache;
|
||||
private final Log log = LogFactory.getLog(getClass());
|
||||
|
||||
|
@ -63,7 +63,7 @@ class ResponseCachingPolicy {
|
|||
* @param sharedCache whether to behave as a shared cache (true) or a
|
||||
* non-shared/private cache (false)
|
||||
*/
|
||||
public ResponseCachingPolicy(int maxObjectSizeBytes, boolean sharedCache) {
|
||||
public ResponseCachingPolicy(long maxObjectSizeBytes, boolean sharedCache) {
|
||||
this.maxObjectSizeBytes = maxObjectSizeBytes;
|
||||
this.sharedCache = sharedCache;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public abstract class AbstractProtocolTest {
|
|||
|
||||
params = new CacheConfig();
|
||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||
params.setMaxObjectSizeBytes(MAX_BYTES);
|
||||
params.setMaxObjectSize(MAX_BYTES);
|
||||
cache = new BasicHttpCache(params);
|
||||
mockBackend = EasyMock.createMock(HttpClient.class);
|
||||
mockCache = EasyMock.createMock(HttpCache.class);
|
||||
|
|
|
@ -75,7 +75,7 @@ public class DoNotTestProtocolRequirements {
|
|||
|
||||
originResponse = make200Response();
|
||||
CacheConfig params = new CacheConfig();
|
||||
params.setMaxObjectSizeBytes(MAX_BYTES);
|
||||
params.setMaxObjectSize(MAX_BYTES);
|
||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||
|
||||
HttpCache cache = new BasicHttpCache(params);
|
||||
|
|
|
@ -234,7 +234,7 @@ public class TestBasicHttpCache {
|
|||
Date responseReceived = new Date(now.getTime() - 1 * 1000L);
|
||||
|
||||
HttpResponse originResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES + 1));
|
||||
originResponse.setEntity(HttpTestUtils.makeBody((int) CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES + 1));
|
||||
originResponse.setHeader("Cache-Control","public, max-age=3600");
|
||||
originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
|
||||
originResponse.setHeader("ETag", "\"etag\"");
|
||||
|
@ -256,7 +256,7 @@ public class TestBasicHttpCache {
|
|||
Date responseReceived = new Date(now.getTime() - 1 * 1000L);
|
||||
|
||||
HttpResponse originResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES - 1));
|
||||
originResponse.setEntity(HttpTestUtils.makeBody((int) CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES - 1));
|
||||
originResponse.setHeader("Cache-Control","public, max-age=3600");
|
||||
originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
|
||||
originResponse.setHeader("ETag", "\"etag\"");
|
||||
|
|
|
@ -94,7 +94,7 @@ public class TestProtocolDeviations {
|
|||
originResponse = make200Response();
|
||||
|
||||
CacheConfig params = new CacheConfig();
|
||||
params.setMaxObjectSizeBytes(MAX_BYTES);
|
||||
params.setMaxObjectSize(MAX_BYTES);
|
||||
params.setMaxCacheEntries(MAX_ENTRIES);
|
||||
|
||||
HttpCache cache = new BasicHttpCache(params);
|
||||
|
|
|
@ -118,7 +118,7 @@ public class TestSizeLimitedResponseReader {
|
|||
@Test
|
||||
public void testTooLargeEntityHasOriginalContentTypes() throws Exception {
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
StringEntity entity = new StringEntity("large entity content", "text/plain", "utf-8");
|
||||
StringEntity entity = new StringEntity("large entity content");
|
||||
response.setEntity(entity);
|
||||
|
||||
impl = new SizeLimitedResponseReader(new HeapResourceFactory(), MAX_SIZE, request, response);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class TestEhcacheProtocolRequirements extends TestProtocolRequirements{
|
|||
public void setUp() {
|
||||
super.setUp();
|
||||
params = new CacheConfig();
|
||||
params.setMaxObjectSizeBytes(MAX_BYTES);
|
||||
params.setMaxObjectSize(MAX_BYTES);
|
||||
|
||||
if (CACHE_MANAGER.cacheExists(TEST_EHCACHE_NAME)){
|
||||
CACHE_MANAGER.removeCache(TEST_EHCACHE_NAME);
|
||||
|
|
Loading…
Reference in New Issue