HTTPCLIENT-1137: The values for the Via header are created by httpclient-cache
for each cached and backend request. Committing patch by alinachegalati at yahoo dot com. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1197713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5dffa49321
commit
d19daa3dcd
|
@ -29,6 +29,7 @@ package org.apache.http.impl.client.cache;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
@ -120,6 +121,8 @@ public class CachingHttpClient implements HttpClient {
|
||||||
private final AtomicLong cacheMisses = new AtomicLong();
|
private final AtomicLong cacheMisses = new AtomicLong();
|
||||||
private final AtomicLong cacheUpdates = new AtomicLong();
|
private final AtomicLong cacheUpdates = new AtomicLong();
|
||||||
|
|
||||||
|
private final Map<ProtocolVersion, String> viaHeaders = new HashMap<ProtocolVersion, String>(4);
|
||||||
|
|
||||||
private final HttpClient backend;
|
private final HttpClient backend;
|
||||||
private final HttpCache responseCache;
|
private final HttpCache responseCache;
|
||||||
private final CacheValidityPolicy validityPolicy;
|
private final CacheValidityPolicy validityPolicy;
|
||||||
|
@ -601,16 +604,25 @@ public class CachingHttpClient implements HttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateViaHeader(HttpMessage msg) {
|
private String generateViaHeader(HttpMessage msg) {
|
||||||
|
|
||||||
|
final ProtocolVersion pv = msg.getProtocolVersion();
|
||||||
|
String existingEntry = viaHeaders.get(pv);
|
||||||
|
if (existingEntry != null) return existingEntry;
|
||||||
|
|
||||||
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
|
final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
|
||||||
final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
|
final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
|
||||||
final ProtocolVersion pv = msg.getProtocolVersion();
|
|
||||||
|
String value;
|
||||||
if ("http".equalsIgnoreCase(pv.getProtocol())) {
|
if ("http".equalsIgnoreCase(pv.getProtocol())) {
|
||||||
return String.format("%d.%d localhost (Apache-HttpClient/%s (cache))",
|
value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getMajor(), pv.getMinor(),
|
||||||
pv.getMajor(), pv.getMinor(), release);
|
release);
|
||||||
} else {
|
} else {
|
||||||
return String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))",
|
value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), pv.getMajor(),
|
||||||
pv.getProtocol(), pv.getMajor(), pv.getMinor(), release);
|
pv.getMinor(), release);
|
||||||
}
|
}
|
||||||
|
viaHeaders.put(pv, value);
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setResponseStatus(final HttpContext context, final CacheResponseStatus value) {
|
private void setResponseStatus(final HttpContext context, final CacheResponseStatus value) {
|
||||||
|
|
Loading…
Reference in New Issue