hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1417343 [1/3] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Wed, 05 Dec 2012 10:34:48 GMT
Author: olegk
Date: Wed Dec  5 10:34:46 2012
New Revision: 1417343

URL: http://svn.apache.org/viewvc?rev=1417343&view=rev
Log:
Ported internal caching classes to the new execution chain API

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidationRequest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/OptionsHttp11Response.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidationRequest.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRequirements.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRequestProtocolCompliance.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseProtocolCompliance.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidationRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidationRequest.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidationRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidationRequest.java Wed Dec  5 10:34:46 2012
@@ -30,9 +30,9 @@ import java.io.IOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
 import org.apache.http.ProtocolException;
 import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -43,7 +43,7 @@ class AsynchronousValidationRequest impl
     private final AsynchronousValidator parent;
     private final CachingHttpClient cachingClient;
     private final HttpHost target;
-    private final HttpRequest request;
+    private final HttpRequestWrapper request;
     private final HttpContext context;
     private final HttpCacheEntry cacheEntry;
     private final String identifier;
@@ -63,7 +63,7 @@ class AsynchronousValidationRequest impl
      */
     AsynchronousValidationRequest(AsynchronousValidator parent,
             CachingHttpClient cachingClient, HttpHost target,
-            HttpRequest request, HttpContext context,
+            HttpRequestWrapper request, HttpContext context,
             HttpCacheEntry cacheEntry,
             String identifier) {
         this.parent = parent;

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/AsynchronousValidator.java Wed Dec  5 10:34:46 2012
@@ -38,8 +38,8 @@ import java.util.concurrent.TimeUnit;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
 import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -101,7 +101,7 @@ class AsynchronousValidator {
      * @param entry
      */
     public synchronized void revalidateCacheEntry(HttpHost target,
-            HttpRequest request, HttpContext context, HttpCacheEntry entry) {
+            HttpRequestWrapper request, HttpContext context, HttpCacheEntry entry) {
         // getVariantURI will fall back on getURI if no variants exist
         String uri = cacheKeyGenerator.getVariantURI(target, request, entry);
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java Wed Dec  5 10:34:46 2012
@@ -58,6 +58,7 @@ import org.apache.http.client.cache.Head
 import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.cache.HttpCacheStorage;
 import org.apache.http.client.cache.ResourceFactory;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.impl.client.DefaultHttpClient;
@@ -403,14 +404,20 @@ public class CachingHttpClient implement
         return backend.getParams();
     }
 
-    public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
+    public HttpResponse execute(HttpHost target, HttpRequest originalRequest, HttpContext context)
             throws IOException {
 
+        HttpRequestWrapper request;
+        if (originalRequest instanceof HttpRequestWrapper) {
+            request = ((HttpRequestWrapper) originalRequest);
+        } else {
+            request = HttpRequestWrapper.wrap(originalRequest);
+        }
+        String via = generateViaHeader(originalRequest);
+
         // default response context
         setResponseStatus(context, CacheResponseStatus.CACHE_MISS);
 
-        String via = generateViaHeader(request);
-
         if (clientRequestsOurOptions(request)) {
             setResponseStatus(context, CacheResponseStatus.CACHE_MODULE_RESPONSE);
             return new OptionsHttp11Response();
@@ -420,7 +427,7 @@ public class CachingHttpClient implement
                 request, context);
         if (fatalErrorResponse != null) return fatalErrorResponse;
 
-        request = requestCompliance.makeRequestCompliant(request);
+        requestCompliance.makeRequestCompliant(request);
         request.addHeader("Via",via);
 
         flushEntriesInvalidatedByRequest(target, request);
@@ -439,7 +446,7 @@ public class CachingHttpClient implement
         return handleCacheHit(target, request, context, entry);
     }
 
-    private HttpResponse handleCacheHit(HttpHost target, HttpRequest request,
+    private HttpResponse handleCacheHit(HttpHost target, HttpRequestWrapper request,
             HttpContext context, HttpCacheEntry entry)
             throws ClientProtocolException, IOException {
         recordCacheHit(target, request);
@@ -468,7 +475,7 @@ public class CachingHttpClient implement
     }
 
     private HttpResponse revalidateCacheEntry(HttpHost target,
-            HttpRequest request, HttpContext context, HttpCacheEntry entry,
+            HttpRequestWrapper request, HttpContext context, HttpCacheEntry entry,
             Date now) throws ClientProtocolException {
 
         try {
@@ -490,7 +497,7 @@ public class CachingHttpClient implement
         }
     }
 
-    private HttpResponse handleCacheMiss(HttpHost target, HttpRequest request,
+    private HttpResponse handleCacheMiss(HttpHost target, HttpRequestWrapper request,
             HttpContext context) throws IOException {
         recordCacheMiss(target, request);
 
@@ -508,7 +515,7 @@ public class CachingHttpClient implement
         return callBackend(target, request, context);
     }
 
-    private HttpCacheEntry satisfyFromCache(HttpHost target, HttpRequest request) {
+    private HttpCacheEntry satisfyFromCache(HttpHost target, HttpRequestWrapper request) {
         HttpCacheEntry entry = null;
         try {
             entry = responseCache.getCacheEntry(target, request);
@@ -518,7 +525,7 @@ public class CachingHttpClient implement
         return entry;
     }
 
-    private HttpResponse getFatallyNoncompliantResponse(HttpRequest request,
+    private HttpResponse getFatallyNoncompliantResponse(HttpRequestWrapper request,
             HttpContext context) {
         HttpResponse fatalErrorResponse = null;
         List<RequestProtocolError> fatalError = requestCompliance.requestIsFatallyNonCompliant(request);
@@ -531,7 +538,7 @@ public class CachingHttpClient implement
     }
 
     private Map<String, Variant> getExistingCacheVariants(HttpHost target,
-            HttpRequest request) {
+            HttpRequestWrapper request) {
         Map<String,Variant> variants = null;
         try {
             variants = responseCache.getVariantCacheEntriesWithEtags(target, request);
@@ -541,7 +548,7 @@ public class CachingHttpClient implement
         return variants;
     }
 
-    private void recordCacheMiss(HttpHost target, HttpRequest request) {
+    private void recordCacheMiss(HttpHost target, HttpRequestWrapper request) {
         cacheMisses.getAndIncrement();
         if (log.isTraceEnabled()) {
             RequestLine rl = request.getRequestLine();
@@ -549,7 +556,7 @@ public class CachingHttpClient implement
         }
     }
 
-    private void recordCacheHit(HttpHost target, HttpRequest request) {
+    private void recordCacheHit(HttpHost target, HttpRequestWrapper request) {
         cacheHits.getAndIncrement();
         if (log.isTraceEnabled()) {
             RequestLine rl = request.getRequestLine();
@@ -563,7 +570,7 @@ public class CachingHttpClient implement
     }
 
     private void flushEntriesInvalidatedByRequest(HttpHost target,
-            HttpRequest request) {
+            HttpRequestWrapper request) {
         try {
             responseCache.flushInvalidatedCacheEntriesFor(target, request);
         } catch (IOException ioe) {
@@ -571,7 +578,7 @@ public class CachingHttpClient implement
         }
     }
 
-    private HttpResponse generateCachedResponse(HttpRequest request,
+    private HttpResponse generateCachedResponse(HttpRequestWrapper request,
             HttpContext context, HttpCacheEntry entry, Date now) {
         final HttpResponse cachedResponse;
         if (request.containsHeader(HeaderConstants.IF_NONE_MATCH)
@@ -587,7 +594,7 @@ public class CachingHttpClient implement
         return cachedResponse;
     }
 
-    private HttpResponse handleRevalidationFailure(HttpRequest request,
+    private HttpResponse handleRevalidationFailure(HttpRequestWrapper request,
             HttpContext context, HttpCacheEntry entry, Date now) {
         if (staleResponseNotAllowed(request, entry, now)) {
             return generateGatewayTimeout(context);
@@ -610,14 +617,14 @@ public class CachingHttpClient implement
         return cachedResponse;
     }
 
-    private boolean staleResponseNotAllowed(HttpRequest request,
+    private boolean staleResponseNotAllowed(HttpRequestWrapper request,
             HttpCacheEntry entry, Date now) {
         return validityPolicy.mustRevalidate(entry)
             || (isSharedCache() && validityPolicy.proxyRevalidate(entry))
             || explicitFreshnessRequest(request, entry, now);
     }
 
-    private boolean mayCallBackend(HttpRequest request) {
+    private boolean mayCallBackend(HttpRequestWrapper request) {
         for (Header h: request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
             for (HeaderElement elt : h.getElements()) {
                 if ("only-if-cached".equals(elt.getName())) {
@@ -629,7 +636,7 @@ public class CachingHttpClient implement
         return true;
     }
 
-    private boolean explicitFreshnessRequest(HttpRequest request, HttpCacheEntry entry, Date now) {
+    private boolean explicitFreshnessRequest(HttpRequestWrapper request, HttpCacheEntry entry, Date now) {
         for(Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
             for(HeaderElement elt : h.getElements()) {
                 if (HeaderConstants.CACHE_CONTROL_MAX_STALE.equals(elt.getName())) {
@@ -718,7 +725,7 @@ public class CachingHttpClient implement
         return true;
     }
 
-    HttpResponse callBackend(HttpHost target, HttpRequest request, HttpContext context)
+    HttpResponse callBackend(HttpHost target, HttpRequestWrapper request, HttpContext context)
             throws IOException {
 
         Date requestDate = getCurrentDate();
@@ -751,9 +758,10 @@ public class CachingHttpClient implement
     }
 
     HttpResponse negotiateResponseFromVariants(HttpHost target,
-            HttpRequest request, HttpContext context,
+            HttpRequestWrapper request, HttpContext context,
             Map<String, Variant> variants) throws IOException {
-        HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequestFromVariants(request, variants);
+        HttpRequestWrapper conditionalRequest = conditionalRequestBuilder
+            .buildConditionalRequestFromVariants(request, variants);
 
         Date requestDate = getCurrentDate();
         HttpResponse backendResponse = backend.execute(target, conditionalRequest, context);
@@ -803,15 +811,15 @@ public class CachingHttpClient implement
     }
 
     private HttpResponse retryRequestUnconditionally(HttpHost target,
-            HttpRequest request, HttpContext context,
+            HttpRequestWrapper request, HttpContext context,
             HttpCacheEntry matchedEntry) throws IOException {
-        HttpRequest unconditional = conditionalRequestBuilder
+        HttpRequestWrapper unconditional = conditionalRequestBuilder
             .buildUnconditionalRequest(request, matchedEntry);
         return callBackend(target, unconditional, context);
     }
 
     private HttpCacheEntry getUpdatedVariantEntry(HttpHost target,
-            HttpRequest conditionalRequest, Date requestDate,
+            HttpRequestWrapper conditionalRequest, Date requestDate,
             Date responseDate, HttpResponse backendResponse,
             Variant matchingVariant, HttpCacheEntry matchedEntry) {
         HttpCacheEntry responseEntry = matchedEntry;
@@ -824,7 +832,7 @@ public class CachingHttpClient implement
         return responseEntry;
     }
 
-    private void tryToUpdateVariantMap(HttpHost target, HttpRequest request,
+    private void tryToUpdateVariantMap(HttpHost target, HttpRequestWrapper request,
             Variant matchingVariant) {
         try {
             responseCache.reuseVariantEntryFor(target, request, matchingVariant);
@@ -833,7 +841,7 @@ public class CachingHttpClient implement
         }
     }
 
-    private boolean shouldSendNotModifiedResponse(HttpRequest request,
+    private boolean shouldSendNotModifiedResponse(HttpRequestWrapper request,
             HttpCacheEntry responseEntry) {
         return (suitabilityChecker.isConditional(request)
                 && suitabilityChecker.allConditionalsMatch(request, responseEntry, new Date()));
@@ -841,11 +849,11 @@ public class CachingHttpClient implement
 
     HttpResponse revalidateCacheEntry(
             HttpHost target,
-            HttpRequest request,
+            HttpRequestWrapper request,
             HttpContext context,
             HttpCacheEntry cacheEntry) throws IOException, ProtocolException {
 
-        HttpRequest conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
+        HttpRequestWrapper conditionalRequest = conditionalRequestBuilder.buildConditionalRequest(request, cacheEntry);
 
         Date requestDate = getCurrentDate();
         HttpResponse backendResponse = backend.execute(target, conditionalRequest, context);
@@ -900,7 +908,7 @@ public class CachingHttpClient implement
 
     HttpResponse handleBackendResponse(
             HttpHost target,
-            HttpRequest request,
+            HttpRequestWrapper request,
             Date requestDate,
             Date responseDate,
             HttpResponse backendResponse) throws IOException {
@@ -929,7 +937,7 @@ public class CachingHttpClient implement
         return backendResponse;
     }
 
-    private boolean alreadyHaveNewerCacheEntry(HttpHost target, HttpRequest request,
+    private boolean alreadyHaveNewerCacheEntry(HttpHost target, HttpRequestWrapper request,
             HttpResponse backendResponse) {
         HttpCacheEntry existing = null;
         try {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ConditionalRequestBuilder.java Wed Dec  5 10:34:46 2012
@@ -28,8 +28,6 @@ package org.apache.http.impl.client.cach
 
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpRequest;
@@ -37,7 +35,7 @@ import org.apache.http.ProtocolException
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.cache.HttpCacheEntry;
-import org.apache.http.impl.client.RequestWrapper;
+import org.apache.http.client.methods.HttpRequestWrapper;
 
 /**
  * @since 4.1
@@ -45,8 +43,6 @@ import org.apache.http.impl.client.Reque
 @Immutable
 class ConditionalRequestBuilder {
 
-    private static final Log log = LogFactory.getLog(ConditionalRequestBuilder.class);
-
     /**
      * When a {@link HttpCacheEntry} is stale but 'might' be used as a response
      * to an {@link HttpRequest} we will attempt to revalidate the entry with
@@ -57,17 +53,17 @@ class ConditionalRequestBuilder {
      * @return the wrapped request
      * @throws ProtocolException when I am unable to build a new origin request.
      */
-    public HttpRequest buildConditionalRequest(HttpRequest request, HttpCacheEntry cacheEntry)
+    public HttpRequestWrapper buildConditionalRequest(HttpRequestWrapper request, HttpCacheEntry cacheEntry)
             throws ProtocolException {
-        RequestWrapper wrapperRequest = new RequestWrapper(request);
-        wrapperRequest.resetHeaders();
+        HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
+        newRequest.setHeaders(request.getAllHeaders());
         Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
         if (eTag != null) {
-            wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
+            newRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
         }
         Header lastModified = cacheEntry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
         if (lastModified != null) {
-            wrapperRequest.setHeader(HeaderConstants.IF_MODIFIED_SINCE, lastModified.getValue());
+            newRequest.setHeader(HeaderConstants.IF_MODIFIED_SINCE, lastModified.getValue());
         }
         boolean mustRevalidate = false;
         for(Header h : cacheEntry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
@@ -80,9 +76,9 @@ class ConditionalRequestBuilder {
             }
         }
         if (mustRevalidate) {
-            wrapperRequest.addHeader(HeaderConstants.CACHE_CONTROL, HeaderConstants.CACHE_CONTROL_MAX_AGE + "=0");
+            newRequest.addHeader(HeaderConstants.CACHE_CONTROL, HeaderConstants.CACHE_CONTROL_MAX_AGE + "=0");
         }
-        return wrapperRequest;
+        return newRequest;
 
     }
 
@@ -96,16 +92,10 @@ class ConditionalRequestBuilder {
      * @param variants
      * @return the wrapped request
      */
-    public HttpRequest buildConditionalRequestFromVariants(HttpRequest request,
+    public HttpRequestWrapper buildConditionalRequestFromVariants(HttpRequestWrapper request,
             Map<String, Variant> variants) {
-        RequestWrapper wrapperRequest;
-        try {
-            wrapperRequest = new RequestWrapper(request);
-        } catch (ProtocolException pe) {
-            log.warn("unable to build conditional request", pe);
-            return request;
-        }
-        wrapperRequest.resetHeaders();
+        HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
+        newRequest.setHeaders(request.getAllHeaders());
 
         // we do not support partial content so all etags are used
         StringBuilder etags = new StringBuilder();
@@ -118,8 +108,8 @@ class ConditionalRequestBuilder {
             etags.append(etag);
         }
 
-        wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH, etags.toString());
-        return wrapperRequest;
+        newRequest.setHeader(HeaderConstants.IF_NONE_MATCH, etags.toString());
+        return newRequest;
     }
 
     /**
@@ -133,23 +123,17 @@ class ConditionalRequestBuilder {
      * @param entry existing cache entry we are trying to validate
      * @return an unconditional validation request
      */
-    public HttpRequest buildUnconditionalRequest(HttpRequest request, HttpCacheEntry entry) {
-        RequestWrapper wrapped;
-        try {
-            wrapped = new RequestWrapper(request);
-        } catch (ProtocolException e) {
-            log.warn("unable to build proper unconditional request", e);
-            return request;
-        }
-        wrapped.resetHeaders();
-        wrapped.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
-        wrapped.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
-        wrapped.removeHeaders(HeaderConstants.IF_RANGE);
-        wrapped.removeHeaders(HeaderConstants.IF_MATCH);
-        wrapped.removeHeaders(HeaderConstants.IF_NONE_MATCH);
-        wrapped.removeHeaders(HeaderConstants.IF_UNMODIFIED_SINCE);
-        wrapped.removeHeaders(HeaderConstants.IF_MODIFIED_SINCE);
-        return wrapped;
+    public HttpRequestWrapper buildUnconditionalRequest(HttpRequestWrapper request, HttpCacheEntry entry) {
+        HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(request.getOriginal());
+        newRequest.setHeaders(request.getAllHeaders());
+        newRequest.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
+        newRequest.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
+        newRequest.removeHeaders(HeaderConstants.IF_RANGE);
+        newRequest.removeHeaders(HeaderConstants.IF_MATCH);
+        newRequest.removeHeaders(HeaderConstants.IF_NONE_MATCH);
+        newRequest.removeHeaders(HeaderConstants.IF_UNMODIFIED_SINCE);
+        newRequest.removeHeaders(HeaderConstants.IF_MODIFIED_SINCE);
+        return newRequest;
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/OptionsHttp11Response.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/OptionsHttp11Response.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/OptionsHttp11Response.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/OptionsHttp11Response.java Wed Dec  5 10:34:46 2012
@@ -45,6 +45,7 @@ import org.apache.http.params.HttpParams
 /**
  * @since 4.1
  */
+@SuppressWarnings("deprecation")
 @Immutable
 final class OptionsHttp11Response extends AbstractHttpMessage implements HttpResponse {
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/RequestProtocolCompliance.java Wed Dec  5 10:34:46 2012
@@ -37,14 +37,13 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.cache.HeaderConstants;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.entity.AbstractHttpEntity;
 import org.apache.http.entity.ContentType;
-import org.apache.http.impl.client.RequestWrapper;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.message.BasicStatusLine;
@@ -95,7 +94,7 @@ class RequestProtocolCompliance {
      * @return the updated request
      * @throws ClientProtocolException when we have trouble making the request compliant
      */
-    public HttpRequest makeRequestCompliant(HttpRequest request)
+    public void makeRequestCompliant(HttpRequestWrapper request)
         throws ClientProtocolException {
 
         if (requestMustNotHaveEntity(request)) {
@@ -107,15 +106,10 @@ class RequestProtocolCompliance {
         decrementOPTIONSMaxForwardsIfGreaterThen0(request);
         stripOtherFreshnessDirectivesWithNoCache(request);
 
-        if (requestVersionIsTooLow(request)) {
-            return upgradeRequestTo(request, HttpVersion.HTTP_1_1);
+        if (requestVersionIsTooLow(request)
+                || requestMinorVersionIsTooHighMajorVersionsMatch(request)) {
+            request.setProtocolVersion(HttpVersion.HTTP_1_1);
         }
-
-        if (requestMinorVersionIsTooHighMajorVersionsMatch(request)) {
-            return downgradeRequestTo(request, HttpVersion.HTTP_1_1);
-        }
-
-        return request;
     }
 
     private void stripOtherFreshnessDirectivesWithNoCache(HttpRequest request) {
@@ -248,32 +242,6 @@ class RequestProtocolCompliance {
         }
     }
 
-    private HttpRequest upgradeRequestTo(HttpRequest request, ProtocolVersion version)
-            throws ClientProtocolException {
-        RequestWrapper newRequest;
-        try {
-            newRequest = new RequestWrapper(request);
-        } catch (ProtocolException pe) {
-            throw new ClientProtocolException(pe);
-        }
-        newRequest.setProtocolVersion(version);
-
-        return newRequest;
-    }
-
-    private HttpRequest downgradeRequestTo(HttpRequest request, ProtocolVersion version)
-            throws ClientProtocolException {
-        RequestWrapper newRequest;
-        try {
-            newRequest = new RequestWrapper(request);
-        } catch (ProtocolException pe) {
-            throw new ClientProtocolException(pe);
-        }
-        newRequest.setProtocolVersion(version);
-
-        return newRequest;
-    }
-
     protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(HttpRequest request) {
         ProtocolVersion requestProtocol = request.getProtocolVersion();
         if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) {

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ResponseProtocolCompliance.java Wed Dec  5 10:34:46 2012
@@ -39,11 +39,10 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.cache.HeaderConstants;
-import org.apache.http.impl.client.RequestWrapper;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.impl.cookie.DateParseException;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
@@ -69,7 +68,7 @@ class ResponseProtocolCompliance {
      * @param response The {@link HttpResponse} from the origin server
      * @throws IOException Bad things happened
      */
-    public void ensureProtocolCompliance(HttpRequest request, HttpResponse response)
+    public void ensureProtocolCompliance(HttpRequestWrapper request, HttpResponse response)
             throws IOException {
         if (backendResponseMustNotHaveBody(request, response)) {
             consumeBody(response);
@@ -213,14 +212,13 @@ class ResponseProtocolCompliance {
                 || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED;
     }
 
-    private void requestDidNotExpect100ContinueButResponseIsOne(HttpRequest request,
+    private void requestDidNotExpect100ContinueButResponseIsOne(HttpRequestWrapper request,
             HttpResponse response) throws IOException {
         if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) {
             return;
         }
 
-        HttpRequest originalRequest = requestWasWrapped(request) ?
-                ((RequestWrapper)request).getOriginal() : request;
+        HttpRequest originalRequest = request.getOriginal();
         if (originalRequest instanceof HttpEntityEnclosingRequest) {
             if (((HttpEntityEnclosingRequest)originalRequest).expectContinue()) return;
         }
@@ -228,14 +226,10 @@ class ResponseProtocolCompliance {
         throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
     }
 
-    private void transferEncodingIsNotReturnedTo1_0Client(HttpRequest request, HttpResponse response) {
-        if (!requestWasWrapped(request)) {
-            return;
-        }
-
-        ProtocolVersion originalProtocol = getOriginalRequestProtocol((RequestWrapper) request);
-
-        if (originalProtocol.compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
+    private void transferEncodingIsNotReturnedTo1_0Client(HttpRequestWrapper request,
+            HttpResponse response) {
+        HttpRequest originalRequest = request.getOriginal();
+        if (originalRequest.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
             return;
         }
 
@@ -247,12 +241,4 @@ class ResponseProtocolCompliance {
         response.removeHeaders(HTTP.TRANSFER_ENCODING);
     }
 
-    private ProtocolVersion getOriginalRequestProtocol(RequestWrapper request) {
-        return request.getOriginal().getProtocolVersion();
-    }
-
-    private boolean requestWasWrapped(HttpRequest request) {
-        return request instanceof RequestWrapper;
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/AbstractProtocolTest.java Wed Dec  5 10:34:46 2012
@@ -33,6 +33,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.protocol.HttpContext;
 import org.easymock.IExpectationSetters;
@@ -48,7 +49,7 @@ public abstract class AbstractProtocolTe
     protected HttpEntity body;
     protected HttpClient mockBackend;
     protected HttpCache mockCache;
-    protected HttpRequest request;
+    protected HttpRequestWrapper request;
     protected HttpResponse originResponse;
     protected CacheConfig config;
     protected CachingHttpClient impl;
@@ -65,7 +66,7 @@ public abstract class AbstractProtocolTe
 
         body = HttpTestUtils.makeBody(entityLength);
 
-        request = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1));
 
         originResponse = HttpTestUtils.make200Response();
 

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidationRequest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidationRequest.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidationRequest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidationRequest.java Wed Dec  5 10:34:46 2012
@@ -29,10 +29,10 @@ package org.apache.http.impl.client.cach
 import java.io.IOException;
 
 import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
 import org.apache.http.ProtocolException;
 import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.protocol.HttpContext;
 import org.easymock.classextension.EasyMock;
 import org.junit.Before;
@@ -43,7 +43,7 @@ public class TestAsynchronousValidationR
     private AsynchronousValidator mockParent;
     private CachingHttpClient mockClient;
     private HttpHost target;
-    private HttpRequest request;
+    private HttpRequestWrapper request;
     private HttpContext mockContext;
     private HttpCacheEntry mockCacheEntry;
 
@@ -52,7 +52,7 @@ public class TestAsynchronousValidationR
         mockParent = EasyMock.createNiceMock(AsynchronousValidator.class);
         mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
         target = new HttpHost("foo.example.com");
-        request = new HttpGet("/");
+        request = HttpRequestWrapper.wrap(new HttpGet("/"));
         mockContext = EasyMock.createNiceMock(HttpContext.class);
         mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java Wed Dec  5 10:34:46 2012
@@ -40,6 +40,7 @@ import org.apache.http.ProtocolException
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.protocol.HttpContext;
 import org.easymock.Capture;
@@ -53,7 +54,7 @@ public class TestAsynchronousValidator {
 
     private CachingHttpClient mockClient;
     private HttpHost target;
-    private HttpRequest request;
+    private HttpRequestWrapper request;
     private HttpContext mockContext;
     private HttpCacheEntry mockCacheEntry;
 
@@ -63,7 +64,7 @@ public class TestAsynchronousValidator {
     public void setUp() {
         mockClient = EasyMock.createNiceMock(CachingHttpClient.class);
         target = new HttpHost("foo.example.com");
-        request = new HttpGet("/");
+        request = HttpRequestWrapper.wrap(new HttpGet("/"));
         mockContext = EasyMock.createNiceMock(HttpContext.class);
         mockCacheEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
 
@@ -156,8 +157,8 @@ public class TestAsynchronousValidator {
         EasyMock.expectLastCall().times(2);
 
         replayMocks();
-        impl.revalidateCacheEntry(target, req1, mockContext, mockCacheEntry);
-        impl.revalidateCacheEntry(target, req2, mockContext, mockCacheEntry);
+        impl.revalidateCacheEntry(target, HttpRequestWrapper.wrap(req1), mockContext, mockCacheEntry);
+        impl.revalidateCacheEntry(target, HttpRequestWrapper.wrap(req2), mockContext, mockCacheEntry);
         verifyMocks();
 
         Assert.assertEquals(2, impl.getScheduledIdentifiers().size());

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachingHttpClient.java Wed Dec  5 10:34:46 2012
@@ -26,6 +26,22 @@
  */
 package org.apache.http.impl.client.cache;
 
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.same;
+import static org.easymock.classextension.EasyMock.createMockBuilder;
+import static org.easymock.classextension.EasyMock.createNiceMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.net.URI;
@@ -34,6 +50,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
@@ -50,6 +67,7 @@ import org.apache.http.client.cache.Cach
 import org.apache.http.client.cache.HttpCacheEntry;
 import org.apache.http.client.cache.HttpCacheStorage;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.entity.InputStreamEntity;
@@ -57,15 +75,10 @@ import org.apache.http.impl.cookie.DateU
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpResponse;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
 import org.easymock.Capture;
-import static org.easymock.classextension.EasyMock.*;
-import static org.junit.Assert.*;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -106,9 +119,8 @@ public class TestCachingHttpClient {
     private Date requestDate;
     private Date responseDate;
     private HttpHost host;
-    private HttpRequest request;
+    private HttpRequestWrapper request;
     private HttpContext context;
-    private HttpParams params;
     private HttpCacheEntry entry;
     private ConsumableInputStream cis;
 
@@ -138,9 +150,9 @@ public class TestCachingHttpClient {
         requestDate = new Date(System.currentTimeMillis() - 1000);
         responseDate = new Date();
         host = new HttpHost("foo.example.com");
-        request = new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(
+                new BasicHttpRequest("GET", "/stuff", HttpVersion.HTTP_1_1));
         context = new BasicHttpContext();
-        params = new BasicHttpParams();
         entry = HttpTestUtils.makeCacheEntry();
         impl = new CachingHttpClient(
                 mockBackend,
@@ -304,7 +316,6 @@ public class TestCachingHttpClient {
         mockImplMethods(CALL_BACKEND);
 
         callBackendReturnsResponse(mockBackendResponse);
-        requestProtocolValidationIsCalled();
         requestIsFatallyNonCompliant(null);
 
         replayMocks();
@@ -332,7 +343,6 @@ public class TestCachingHttpClient {
         getCacheEntryReturns(null);
         getVariantCacheEntriesReturns(new HashMap<String,Variant>());
 
-        requestProtocolValidationIsCalled();
         requestIsFatallyNonCompliant(null);
 
         callBackendReturnsResponse(mockBackendResponse);
@@ -352,7 +362,6 @@ public class TestCachingHttpClient {
         mockImplMethods(CALL_BACKEND);
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
-        requestProtocolValidationIsCalled();
         requestIsFatallyNonCompliant(null);
 
         getCacheEntryReturns(mockCacheEntry);
@@ -375,7 +384,6 @@ public class TestCachingHttpClient {
         mockImplMethods(REVALIDATE_CACHE_ENTRY);
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
-        requestProtocolValidationIsCalled();
         requestIsFatallyNonCompliant(null);
 
         getCacheEntryReturns(mockCacheEntry);
@@ -400,8 +408,8 @@ public class TestCachingHttpClient {
     public void testRevalidationCallsHandleBackEndResponseWhenNot200Or304() throws Exception {
         mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
 
-        HttpRequest validate =
-            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        HttpRequestWrapper validate =
+            HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
         HttpResponse originResponse =
             new BasicHttpResponse(HttpVersion.HTTP_1_1,
                     HttpStatus.SC_NOT_FOUND, "Not Found");
@@ -429,8 +437,8 @@ public class TestCachingHttpClient {
 
         mockImplMethods(GET_CURRENT_DATE);
 
-        HttpRequest validate =
-            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        HttpRequestWrapper validate =
+            HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
         HttpResponse originResponse =
             new BasicHttpResponse(HttpVersion.HTTP_1_1,
                     HttpStatus.SC_NOT_MODIFIED, "Not Modified");
@@ -455,7 +463,6 @@ public class TestCachingHttpClient {
     public void testSuitableCacheEntryDoesNotCauseBackendRequest() throws Exception {
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
-        requestProtocolValidationIsCalled();
         getCacheEntryReturns(mockCacheEntry);
         cacheEntrySuitable(true);
         responseIsGeneratedFromCache();
@@ -836,29 +843,9 @@ public class TestCachingHttpClient {
     }
 
     @Test
-    public void testUsesBackendsConnectionManager() {
-        expect(mockBackend.getConnectionManager()).andReturn(
-                mockConnectionManager);
-        replayMocks();
-        ClientConnectionManager result = impl.getConnectionManager();
-        verifyMocks();
-        Assert.assertSame(result, mockConnectionManager);
-    }
-
-    @Test
-    public void testUsesBackendsHttpParams() {
-        expect(mockBackend.getParams()).andReturn(params);
-        replayMocks();
-        HttpParams result = impl.getParams();
-        verifyMocks();
-        Assert.assertSame(params, result);
-    }
-
-    @Test
     public void testResponseIsGeneratedWhenCacheEntryIsUsable() throws Exception {
 
         requestIsFatallyNonCompliant(null);
-        requestProtocolValidationIsCalled();
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
         cacheEntrySuitable(true);
@@ -877,7 +864,8 @@ public class TestCachingHttpClient {
         ClientProtocolException expected = new ClientProtocolException("ouch");
 
         requestIsFatallyNonCompliant(null);
-        requestCannotBeMadeCompliantThrows(expected);
+        mockRequestProtocolCompliance.makeRequestCompliant((HttpRequestWrapper)anyObject());
+        expectLastCall().andThrow(expected);
 
         boolean gotException = false;
         replayMocks();
@@ -1839,7 +1827,6 @@ public class TestCachingHttpClient {
         entry = HttpTestUtils.makeCacheEntry(new Header[]{new BasicHeader("Cache-Control", "must-revalidate")});
 
         requestIsFatallyNonCompliant(null);
-        requestProtocolValidationIsCalled();
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
         getCacheEntryReturns(entry);
@@ -1858,7 +1845,6 @@ public class TestCachingHttpClient {
         request.setHeader("Cache-Control", "only-if-cached");
 
         requestIsFatallyNonCompliant(null);
-        requestProtocolValidationIsCalled();
         cacheInvalidatorWasCalled();
         requestPolicyAllowsCaching(true);
         getCacheEntryReturns(entry);
@@ -2033,7 +2019,7 @@ public class TestCachingHttpClient {
     private void callBackendReturnsResponse(HttpResponse response) throws IOException {
         expect(impl.callBackend(
                 (HttpHost)anyObject(),
-                (HttpRequest)anyObject(),
+                (HttpRequestWrapper)anyObject(),
                 (HttpContext)anyObject())).andReturn(response);
     }
 
@@ -2042,7 +2028,7 @@ public class TestCachingHttpClient {
         expect(
                 impl.revalidateCacheEntry(
                         (HttpHost)anyObject(),
-                        (HttpRequest)anyObject(),
+                        (HttpRequestWrapper)anyObject(),
                         (HttpContext)anyObject(),
                         (HttpCacheEntry)anyObject())).andReturn(response);
     }
@@ -2067,7 +2053,7 @@ public class TestCachingHttpClient {
                 (HttpCacheEntry)anyObject(), (Date)anyObject())).andReturn(b);
     }
 
-    private void conditionalRequestBuilderReturns(HttpRequest validate)
+    private void conditionalRequestBuilderReturns(HttpRequestWrapper validate)
             throws Exception {
         expect(mockConditionalRequestBuilder
         .buildConditionalRequest(request, entry))
@@ -2117,7 +2103,7 @@ public class TestCachingHttpClient {
                 (HttpCacheEntry)anyObject())).andReturn(mockCachedResponse);
     }
 
-    private void handleBackendResponseReturnsResponse(HttpRequest request, HttpResponse response)
+    private void handleBackendResponseReturnsResponse(HttpRequestWrapper request, HttpResponse response)
             throws IOException {
         expect(
                 impl.handleBackendResponse(
@@ -2128,18 +2114,6 @@ public class TestCachingHttpClient {
                         (HttpResponse)anyObject())).andReturn(response);
     }
 
-    private void requestProtocolValidationIsCalled() throws Exception {
-        expect(
-                mockRequestProtocolCompliance.makeRequestCompliant(
-                        (HttpRequest)anyObject())).andReturn(request);
-    }
-
-    private void requestCannotBeMadeCompliantThrows(ClientProtocolException exception) throws Exception {
-        expect(
-                mockRequestProtocolCompliance.makeRequestCompliant(
-                        (HttpRequest)anyObject())).andThrow(exception);
-    }
-
     private HttpEntity makeStreamingEntity() {
         byte[] body = HttpTestUtils.getRandomBytes(101);
         ByteArrayInputStream buf = new ByteArrayInputStream(body);

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestConditionalRequestBuilder.java Wed Dec  5 10:34:46 2012
@@ -36,6 +36,7 @@ import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolException;
 import org.apache.http.client.cache.HeaderConstants;
 import org.apache.http.client.cache.HttpCacheEntry;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicHttpRequest;
@@ -46,13 +47,14 @@ import org.junit.Test;
 public class TestConditionalRequestBuilder {
 
     private ConditionalRequestBuilder impl;
-    private HttpRequest request;
+    private HttpRequestWrapper request;
     private HttpCacheEntry entry;
 
     @Before
     public void setUp() throws Exception {
         impl = new ConditionalRequestBuilder();
-        request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(
+                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
         entry = HttpTestUtils.makeCacheEntry();
     }
 
@@ -64,13 +66,14 @@ public class TestConditionalRequestBuild
 
         HttpRequest request = new BasicHttpRequest(theMethod, theUri);
         request.addHeader("Accept-Encoding", "gzip");
+        HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
 
         Header[] headers = new Header[] {
                 new BasicHeader("Date", DateUtils.formatDate(new Date())),
                 new BasicHeader("Last-Modified", lastModified) };
 
         HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
-        HttpRequest newRequest = impl.buildConditionalRequest(request, cacheEntry);
+        HttpRequestWrapper newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
 
         Assert.assertNotSame(request, newRequest);
 
@@ -101,8 +104,9 @@ public class TestConditionalRequestBuild
             new BasicHeader("ETag", etag)
         };
         HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
         HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
-        HttpRequest result = impl.buildConditionalRequest(request, entry);
+        HttpRequest result = impl.buildConditionalRequest(requestWrapper, entry);
         Assert.assertEquals(lmDate,
                 result.getFirstHeader("If-Modified-Since").getValue());
         Assert.assertEquals(etag,
@@ -117,6 +121,7 @@ public class TestConditionalRequestBuild
 
         HttpRequest request = new BasicHttpRequest(theMethod, theUri);
         request.addHeader("Accept-Encoding", "gzip");
+        HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
 
         Header[] headers = new Header[] {
                 new BasicHeader("Date", DateUtils.formatDate(new Date())),
@@ -125,7 +130,7 @@ public class TestConditionalRequestBuild
 
         HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
 
-        HttpRequest newRequest = impl.buildConditionalRequest(request, cacheEntry);
+        HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
 
         Assert.assertNotSame(request, newRequest);
 
@@ -146,6 +151,7 @@ public class TestConditionalRequestBuild
     @Test
     public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
         HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+        HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
         Date now = new Date();
         Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
         Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -157,7 +163,7 @@ public class TestConditionalRequestBuild
                 new BasicHeader("Cache-Control","max-age=5, must-revalidate") };
         HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
 
-        HttpRequest result = impl.buildConditionalRequest(request, cacheEntry);
+        HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
 
         boolean foundMaxAge0 = false;
         for(Header h : result.getHeaders("Cache-Control")) {
@@ -174,6 +180,7 @@ public class TestConditionalRequestBuild
     @Test
     public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
         HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+        HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
         Date now = new Date();
         Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
         Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -185,7 +192,7 @@ public class TestConditionalRequestBuild
                 new BasicHeader("Cache-Control","max-age=5, proxy-revalidate") };
         HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(elevenSecondsAgo, nineSecondsAgo, cacheEntryHeaders);
 
-        HttpRequest result = impl.buildConditionalRequest(request, cacheEntry);
+        HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
 
         boolean foundMaxAge0 = false;
         for(Header h : result.getHeaders("Cache-Control")) {
@@ -210,7 +217,7 @@ public class TestConditionalRequestBuild
     public void testBuildUnconditionalRequestUsesRequestUri()
         throws Exception {
         final String uri = "/theURI";
-        request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1));
         HttpRequest result = impl.buildUnconditionalRequest(request, entry);
         Assert.assertEquals(uri, result.getRequestLine().getUri());
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestProtocolRecommendations.java Wed Dec  5 10:34:46 2012
@@ -46,6 +46,7 @@ import static org.apache.http.impl.cooki
 
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpResponse;
@@ -672,7 +673,7 @@ public class TestProtocolRecommendations
             new BasicHttpEntityEnclosingRequest("POST", "/", HttpVersion.HTTP_1_1);
         post.setEntity(HttpTestUtils.makeBody(128));
         post.setHeader("Content-Length","128");
-        request = post;
+        request = HttpRequestWrapper.wrap(post);
         testDoesNotModifyHeaderOnRequests("Content-Length");
     }
 
@@ -692,7 +693,7 @@ public class TestProtocolRecommendations
         post.setEntity(HttpTestUtils.makeBody(128));
         post.setHeader("Content-Length","128");
         post.setHeader("Content-MD5","Q2hlY2sgSW50ZWdyaXR5IQ==");
-        request = post;
+        request = HttpRequestWrapper.wrap(post);
         testDoesNotModifyHeaderOnRequests("Content-MD5");
     }
 
@@ -712,7 +713,7 @@ public class TestProtocolRecommendations
         put.setEntity(HttpTestUtils.makeBody(128));
         put.setHeader("Content-Length","128");
         put.setHeader("Content-Range","bytes 0-127/256");
-        request = put;
+        request = HttpRequestWrapper.wrap(put);
         testDoesNotModifyHeaderOnRequests("Content-Range");
     }
 
@@ -735,7 +736,7 @@ public class TestProtocolRecommendations
         post.setEntity(HttpTestUtils.makeBody(128));
         post.setHeader("Content-Length","128");
         post.setHeader("Content-Type","application/octet-stream");
-        request = post;
+        request = HttpRequestWrapper.wrap(post);
         testDoesNotModifyHeaderOnRequests("Content-Type");
     }
 
@@ -784,7 +785,7 @@ public class TestProtocolRecommendations
     @Test
     public void testDoesNotModifyIfMatchOnRequests()
         throws Exception {
-        request = new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1));
         request.setHeader("If-Match", "\"etag\"");
         testDoesNotModifyHeaderOnRequests("If-Match");
     }
@@ -814,7 +815,7 @@ public class TestProtocolRecommendations
     @Test
     public void testDoesNotModifyIfUnmodifiedSinceOnRequests()
         throws Exception {
-        request = new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1);
+        request = HttpRequestWrapper.wrap(new BasicHttpRequest("DELETE", "/", HttpVersion.HTTP_1_1));
         request.setHeader("If-Unmodified-Since", formatDate(new Date()));
         testDoesNotModifyHeaderOnRequests("If-Unmodified-Since");
     }



Mime
View raw message