Tab police
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1055725 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3b4b68fe68
commit
4896d1752c
|
@ -228,7 +228,7 @@ public class HttpCacheEntry implements Serializable {
|
||||||
public Map<String, String> getVariantMap() {
|
public Map<String, String> getVariantMap() {
|
||||||
if (variantMap == null) {
|
if (variantMap == null) {
|
||||||
throw new UnsupportedOperationException("variant maps not" +
|
throw new UnsupportedOperationException("variant maps not" +
|
||||||
"supported if constructed with deprecated variant set");
|
"supported if constructed with deprecated variant set");
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(variantMap);
|
return Collections.unmodifiableMap(variantMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,12 +100,12 @@ class CacheEntryUpdater {
|
||||||
|
|
||||||
if (entryAndResponseHaveDateHeader(entry, response)
|
if (entryAndResponseHaveDateHeader(entry, response)
|
||||||
&& entryDateHeaderNewerThenResponse(entry, response)) {
|
&& entryDateHeaderNewerThenResponse(entry, response)) {
|
||||||
// Don't merge headers, keep the entry's headers as they are newer.
|
// Don't merge headers, keep the entry's headers as they are newer.
|
||||||
return entry.getAllHeaders();
|
return entry.getAllHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry
|
List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry
|
||||||
.getAllHeaders()));
|
.getAllHeaders()));
|
||||||
removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response);
|
removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response);
|
||||||
removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry);
|
removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry);
|
||||||
cacheEntryHeaderList.addAll(Arrays.asList(response.getAllHeaders()));
|
cacheEntryHeaderList.addAll(Arrays.asList(response.getAllHeaders()));
|
||||||
|
|
|
@ -666,8 +666,8 @@ public class CachingHttpClient implements HttpClient {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean revalidationResponseIsTooOld(HttpResponse backendResponse,
|
private boolean revalidationResponseIsTooOld(HttpResponse backendResponse,
|
||||||
HttpCacheEntry cacheEntry) {
|
HttpCacheEntry cacheEntry) {
|
||||||
final Header entryDateHeader = cacheEntry.getFirstHeader("Date");
|
final Header entryDateHeader = cacheEntry.getFirstHeader("Date");
|
||||||
final Header responseDateHeader = backendResponse.getFirstHeader("Date");
|
final Header responseDateHeader = backendResponse.getFirstHeader("Date");
|
||||||
if (entryDateHeader != null && responseDateHeader != null) {
|
if (entryDateHeader != null && responseDateHeader != null) {
|
||||||
|
@ -682,8 +682,8 @@ public class CachingHttpClient implements HttpClient {
|
||||||
// unconditional retry recommended in 13.2.6 of RFC 2616.
|
// unconditional retry recommended in 13.2.6 of RFC 2616.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse negotiateResponseFromVariants(HttpHost target,
|
HttpResponse negotiateResponseFromVariants(HttpHost target,
|
||||||
HttpRequest request, HttpContext context,
|
HttpRequest request, HttpContext context,
|
||||||
|
@ -716,7 +716,7 @@ public class CachingHttpClient implements HttpClient {
|
||||||
HttpCacheEntry matchedEntry = matchingVariant.getEntry();
|
HttpCacheEntry matchedEntry = matchingVariant.getEntry();
|
||||||
|
|
||||||
if (revalidationResponseIsTooOld(backendResponse, matchedEntry)) {
|
if (revalidationResponseIsTooOld(backendResponse, matchedEntry)) {
|
||||||
return retryRequestUnconditionally(target, request, context,
|
return retryRequestUnconditionally(target, request, context,
|
||||||
matchedEntry);
|
matchedEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ public class CachingHttpClient implements HttpClient {
|
||||||
HttpRequest request, HttpContext context,
|
HttpRequest request, HttpContext context,
|
||||||
HttpCacheEntry matchedEntry) throws IOException {
|
HttpCacheEntry matchedEntry) throws IOException {
|
||||||
HttpRequest unconditional = conditionalRequestBuilder
|
HttpRequest unconditional = conditionalRequestBuilder
|
||||||
.buildUnconditionalRequest(request, matchedEntry);
|
.buildUnconditionalRequest(request, matchedEntry);
|
||||||
return callBackend(target, unconditional, context);
|
return callBackend(target, unconditional, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,18 +779,18 @@ public class CachingHttpClient implements HttpClient {
|
||||||
HttpContext context,
|
HttpContext context,
|
||||||
HttpCacheEntry cacheEntry) throws IOException, ProtocolException {
|
HttpCacheEntry cacheEntry) throws IOException, ProtocolException {
|
||||||
|
|
||||||
HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
|
HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
|
||||||
|
|
||||||
Date requestDate = getCurrentDate();
|
Date requestDate = getCurrentDate();
|
||||||
HttpResponse backendResponse = backend.execute(target, conditionalRequest, context);
|
HttpResponse backendResponse = backend.execute(target, conditionalRequest, context);
|
||||||
Date responseDate = getCurrentDate();
|
Date responseDate = getCurrentDate();
|
||||||
|
|
||||||
if (revalidationResponseIsTooOld(backendResponse, cacheEntry)) {
|
if (revalidationResponseIsTooOld(backendResponse, cacheEntry)) {
|
||||||
HttpRequest unconditional = conditionalRequestBuilder
|
HttpRequest unconditional = conditionalRequestBuilder
|
||||||
.buildUnconditionalRequest(request, cacheEntry);
|
.buildUnconditionalRequest(request, cacheEntry);
|
||||||
requestDate = getCurrentDate();
|
requestDate = getCurrentDate();
|
||||||
backendResponse = backend.execute(target, unconditional, context);
|
backendResponse = backend.execute(target, unconditional, context);
|
||||||
responseDate = getCurrentDate();
|
responseDate = getCurrentDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
backendResponse.addHeader("Via", generateViaHeader(backendResponse));
|
backendResponse.addHeader("Via", generateViaHeader(backendResponse));
|
||||||
|
@ -822,11 +822,11 @@ public class CachingHttpClient implements HttpClient {
|
||||||
backendResponse);
|
backendResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean staleIfErrorAppliesTo(int statusCode) {
|
private boolean staleIfErrorAppliesTo(int statusCode) {
|
||||||
return statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
|
return statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
|
||||||
|| statusCode == HttpStatus.SC_BAD_GATEWAY
|
|| statusCode == HttpStatus.SC_BAD_GATEWAY
|
||||||
|| statusCode == HttpStatus.SC_SERVICE_UNAVAILABLE
|
|| statusCode == HttpStatus.SC_SERVICE_UNAVAILABLE
|
||||||
|| statusCode == HttpStatus.SC_GATEWAY_TIMEOUT;
|
|| statusCode == HttpStatus.SC_GATEWAY_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse handleBackendResponse(
|
HttpResponse handleBackendResponse(
|
||||||
|
|
|
@ -31,25 +31,25 @@ import org.apache.http.client.cache.HttpCacheEntry;
|
||||||
/** Records a set of information describing a cached variant. */
|
/** Records a set of information describing a cached variant. */
|
||||||
class Variant {
|
class Variant {
|
||||||
|
|
||||||
private final String variantKey;
|
private final String variantKey;
|
||||||
private final String cacheKey;
|
private final String cacheKey;
|
||||||
private final HttpCacheEntry entry;
|
private final HttpCacheEntry entry;
|
||||||
|
|
||||||
public Variant(String variantKey, String cacheKey, HttpCacheEntry entry) {
|
public Variant(String variantKey, String cacheKey, HttpCacheEntry entry) {
|
||||||
this.variantKey = variantKey;
|
this.variantKey = variantKey;
|
||||||
this.cacheKey = cacheKey;
|
this.cacheKey = cacheKey;
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVariantKey() {
|
public String getVariantKey() {
|
||||||
return variantKey;
|
return variantKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCacheKey() {
|
public String getCacheKey() {
|
||||||
return cacheKey;
|
return cacheKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpCacheEntry getEntry() {
|
public HttpCacheEntry getEntry() {
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ class WarningValue {
|
||||||
char c = src.charAt(offs);
|
char c = src.charAt(offs);
|
||||||
if (offs + 1 < src.length() && c == '\\'
|
if (offs + 1 < src.length() && c == '\\'
|
||||||
&& isChar(src.charAt(offs+1))) {
|
&& isChar(src.charAt(offs+1))) {
|
||||||
offs += 2; // consume quoted-pair
|
offs += 2; // consume quoted-pair
|
||||||
} else if (c == '\"') {
|
} else if (c == '\"') {
|
||||||
foundEnd = true;
|
foundEnd = true;
|
||||||
offs++;
|
offs++;
|
||||||
|
|
|
@ -5549,7 +5549,7 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
|
||||||
|
|
||||||
|
|
||||||
private void assertValidViaHeader(String via) {
|
private void assertValidViaHeader(String via) {
|
||||||
// Via = "Via" ":" 1#( received-protocol received-by [ comment ] )
|
// Via = "Via" ":" 1#( received-protocol received-by [ comment ] )
|
||||||
// received-protocol = [ protocol-name "/" ] protocol-version
|
// received-protocol = [ protocol-name "/" ] protocol-version
|
||||||
// protocol-name = token
|
// protocol-name = token
|
||||||
// protocol-version = token
|
// protocol-version = token
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class TestRFC5861Compliance extends AbstractProtocolTest {
|
public class TestRFC5861Compliance extends AbstractProtocolTest {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "The stale-if-error Cache-Control extension indicates that when an
|
* "The stale-if-error Cache-Control extension indicates that when an
|
||||||
* error is encountered, a cached stale response MAY be used to satisfy
|
* error is encountered, a cached stale response MAY be used to satisfy
|
||||||
* the request, regardless of other freshness information.When used as a
|
* the request, regardless of other freshness information.When used as a
|
||||||
|
@ -62,11 +62,11 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseIsTrueReturnsStaleEntryWithWarning()
|
public void testStaleIfErrorInResponseIsTrueReturnsStaleEntryWithWarning()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||||
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||||
"public, max-age=5, stale-if-error=60");
|
"public, max-age=5, stale-if-error=60");
|
||||||
|
|
||||||
backendExpectsAnyRequest().andReturn(resp1);
|
backendExpectsAnyRequest().andReturn(resp1);
|
||||||
|
|
||||||
|
@ -183,11 +183,11 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInRequestIsTrueReturnsStaleEntryWithWarning()
|
public void testStaleIfErrorInRequestIsTrueReturnsStaleEntryWithWarning()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||||
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||||
"public, max-age=5");
|
"public, max-age=5");
|
||||||
|
|
||||||
backendExpectsAnyRequest().andReturn(resp1);
|
backendExpectsAnyRequest().andReturn(resp1);
|
||||||
|
|
||||||
|
@ -207,12 +207,12 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInResponseIsFalseReturnsError()
|
public void testStaleIfErrorInResponseIsFalseReturnsError()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||||
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||||
"public, max-age=5, stale-if-error=2");
|
"public, max-age=5, stale-if-error=2");
|
||||||
|
|
||||||
backendExpectsAnyRequest().andReturn(resp1);
|
backendExpectsAnyRequest().andReturn(resp1);
|
||||||
|
|
||||||
|
@ -232,12 +232,12 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStaleIfErrorInRequestIsFalseReturnsError()
|
public void testStaleIfErrorInRequestIsFalseReturnsError()
|
||||||
throws Exception{
|
throws Exception{
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||||
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
|
||||||
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
|
||||||
"public, max-age=5");
|
"public, max-age=5");
|
||||||
|
|
||||||
backendExpectsAnyRequest().andReturn(resp1);
|
backendExpectsAnyRequest().andReturn(resp1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue