Index: src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java =================================================================== --- src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java (revision 1182249) +++ src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java (working copy) @@ -44,7 +44,6 @@ import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; import org.apache.http.ProtocolException; -import org.apache.http.ProtocolVersion; import org.apache.http.RequestLine; import org.apache.http.annotation.ThreadSafe; import org.apache.http.client.ClientProtocolException; @@ -63,7 +62,6 @@ import org.apache.http.message.BasicHttpResponse; import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; -import org.apache.http.util.VersionInfo; /** *
The {@link CachingHttpClient} is meant to be a drop-in replacement for
@@ -119,6 +117,8 @@
private final AtomicLong cacheHits = new AtomicLong();
private final AtomicLong cacheMisses = new AtomicLong();
private final AtomicLong cacheUpdates = new AtomicLong();
+
+ private final ViaHeaderCache viaHeaders = new ViaHeaderCache();
private final HttpClient backend;
private final HttpCache responseCache;
@@ -371,7 +371,7 @@
setResponseStatus(context, CacheResponseStatus.CACHE_MISS);
String via = generateViaHeader(request);
-
+
if (clientRequestsOurOptions(request)) {
setResponseStatus(context, CacheResponseStatus.CACHE_MODULE_RESPONSE);
return new OptionsHttp11Response();
@@ -601,16 +601,7 @@
}
private String generateViaHeader(HttpMessage msg) {
- final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
- final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;
- final ProtocolVersion pv = msg.getProtocolVersion();
- if ("http".equalsIgnoreCase(pv.getProtocol())) {
- return String.format("%d.%d localhost (Apache-HttpClient/%s (cache))",
- pv.getMajor(), pv.getMinor(), release);
- } else {
- return String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))",
- pv.getProtocol(), pv.getMajor(), pv.getMinor(), release);
- }
+ return viaHeaders.generateViaHeader(msg);
}
private void setResponseStatus(final HttpContext context, final CacheResponseStatus value) {
Index: src/main/java/org/apache/http/impl/client/cache/ViaHeaderCache.java
===================================================================
--- src/main/java/org/apache/http/impl/client/cache/ViaHeaderCache.java (revision 0)
+++ src/main/java/org/apache/http/impl/client/cache/ViaHeaderCache.java (revision 0)
@@ -0,0 +1,148 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ *