hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1776187 [3/21] - in /httpcomponents/httpclient/trunk: ./ httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/ httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ httpclient5-cache/src/test/java/org/apache/hc...
Date Tue, 27 Dec 2016 19:48:10 GMT
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java Tue Dec 27 19:48:07 2016
@@ -34,14 +34,15 @@ import java.io.InputStream;
 import org.apache.hc.client5.http.cache.InputLimit;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 
 /**
  * Generates {@link Resource} instances whose body is stored in a temporary file.
  *
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class FileResourceFactory implements ResourceFactory {
 
     private final File cacheDir;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResource.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResource.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResource.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResource.java Tue Dec 27 19:48:07 2016
@@ -30,14 +30,15 @@ import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 
 import org.apache.hc.client5.http.cache.Resource;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 
 /**
  * Cache resource backed by a byte array on the heap.
  *
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class HeapResource implements Resource {
 
     private static final long serialVersionUID = -2078599905620463394L;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HeapResourceFactory.java Tue Dec 27 19:48:07 2016
@@ -33,14 +33,15 @@ import java.io.InputStream;
 import org.apache.hc.client5.http.cache.InputLimit;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 
 /**
  * Generates {@link Resource} instances stored entirely in heap.
  *
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class HeapResourceFactory implements ResourceFactory {
 
     @Override

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCache.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/HttpCache.java Tue Dec 27 19:48:07 2016
@@ -31,7 +31,7 @@ import java.util.Date;
 import java.util.Map;
 
 import org.apache.hc.client5.http.cache.HttpCacheEntry;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
@@ -99,24 +99,9 @@ interface HttpCache {
      * @return the {@link HttpResponse}
      * @throws IOException
      */
-    HttpResponse cacheAndReturnResponse(
-            HttpHost host, HttpRequest request, HttpResponse originResponse,
-            Date requestSent, Date responseReceived)
-        throws IOException;
-
-    /**
-     * Store a {@link HttpResponse} in the cache if possible, and return
-     * @param host
-     * @param request
-     * @param originResponse
-     * @param requestSent
-     * @param responseReceived
-     * @return the {@link HttpResponse}
-     * @throws IOException
-     */
-    CloseableHttpResponse cacheAndReturnResponse(HttpHost host,
-            HttpRequest request, CloseableHttpResponse originResponse,
-            Date requestSent, Date responseReceived)
+    ClassicHttpResponse cacheAndReturnResponse(HttpHost host,
+                                               HttpRequest request, ClassicHttpResponse originResponse,
+                                               Date requestSent, Date responseReceived)
         throws IOException;
 
     /**

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/IOUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/IOUtils.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/IOUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/IOUtils.java Tue Dec 27 19:48:07 2016
@@ -34,10 +34,11 @@ import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.HttpEntity;
 
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class IOUtils {
 
     static void consume(final HttpEntity entity) throws IOException {

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ImmediateSchedulingStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ImmediateSchedulingStrategy.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ImmediateSchedulingStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ImmediateSchedulingStrategy.java Tue Dec 27 19:48:07 2016
@@ -31,7 +31,8 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -40,7 +41,7 @@ import org.apache.hc.core5.util.Args;
  *
  * @since 4.3
  */
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE)
 public class ImmediateSchedulingStrategy implements SchedulingStrategy {
 
     private final ExecutorService executor;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ManagedHttpCacheStorage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ManagedHttpCacheStorage.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ManagedHttpCacheStorage.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ManagedHttpCacheStorage.java Tue Dec 27 19:48:07 2016
@@ -37,7 +37,8 @@ import org.apache.hc.client5.http.cache.
 import org.apache.hc.client5.http.cache.HttpCacheStorage;
 import org.apache.hc.client5.http.cache.HttpCacheUpdateCallback;
 import org.apache.hc.client5.http.cache.Resource;
-import org.apache.hc.core5.annotation.ThreadSafe;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -70,7 +71,7 @@ import org.apache.hc.core5.util.Args;
  *
  * @since 4.1
  */
-@ThreadSafe
+@Contract(threading = ThreadingBehavior.SAFE)
 public class ManagedHttpCacheStorage implements HttpCacheStorage, Closeable {
 
     private final CacheMap entries;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/OptionsHttp11Response.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/OptionsHttp11Response.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/OptionsHttp11Response.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/OptionsHttp11Response.java Tue Dec 27 19:48:07 2016
@@ -26,73 +26,60 @@
  */
 package org.apache.hc.client5.http.impl.cache;
 
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.Locale;
 
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpEntity;
-import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.ProtocolException;
 import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.StatusLine;
-import org.apache.hc.core5.http.message.AbstractHttpMessage;
-import org.apache.hc.core5.http.message.BasicStatusLine;
 
 /**
  * @since 4.1
  */
-@Immutable
-final class OptionsHttp11Response extends AbstractHttpMessage implements HttpResponse {
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+final class OptionsHttp11Response implements ClassicHttpResponse, Serializable {
 
     private static final long serialVersionUID = 1L;
-    private final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
-            HttpStatus.SC_NOT_IMPLEMENTED, "");
-    private final ProtocolVersion version = HttpVersion.HTTP_1_1;
-
-    @Override
-    public StatusLine getStatusLine() {
-        return statusLine;
-    }
 
     @Override
     public int getCode() {
-        return statusLine.getStatusCode();
-    }
-
-    @Override
-    public void setStatusLine(final StatusLine statusline) {
-        // No-op on purpose, this class is not going to be doing any work.
+        return HttpStatus.SC_NOT_IMPLEMENTED;
     }
 
     @Override
-    public void setStatusLine(final ProtocolVersion ver, final int code) {
-        // No-op on purpose, this class is not going to be doing any work.
+    public void setCode(final int code) {
     }
 
     @Override
-    public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) {
-        // No-op on purpose, this class is not going to be doing any work.
+    public String getReasonPhrase() {
+        return null;
     }
 
     @Override
-    public void setStatusCode(final int code) throws IllegalStateException {
-        // No-op on purpose, this class is not going to be doing any work.
+    public void setVersion(final ProtocolVersion version) {
     }
 
     @Override
-    public void setReasonPhrase(final String reason) throws IllegalStateException {
-        // No-op on purpose, this class is not going to be doing any work.
+    public int containsHeaders(final String name) {
+        return 0;
     }
 
     @Override
-    public HttpEntity getEntity() {
+    public Header getSingleHeader(final String name) throws ProtocolException {
         return null;
     }
 
     @Override
-    public void setEntity(final HttpEntity entity) {
+    public void setReasonPhrase(final String reason) throws IllegalStateException {
         // No-op on purpose, this class is not going to be doing any work.
     }
 
@@ -107,33 +94,33 @@ final class OptionsHttp11Response extend
     }
 
     @Override
-    public ProtocolVersion getProtocolVersion() {
-        return version;
+    public ProtocolVersion getVersion() {
+        return HttpVersion.HTTP_1_1;
     }
 
     @Override
     public boolean containsHeader(final String name) {
-        return super.containsHeader(name);
+        return false;
     }
 
     @Override
     public Header[] getHeaders(final String name) {
-        return super.getHeaders(name);
+        return null;
     }
 
     @Override
     public Header getFirstHeader(final String name) {
-        return super.getFirstHeader(name);
+        return null;
     }
 
     @Override
     public Header getLastHeader(final String name) {
-        return super.getLastHeader(name);
+        return null;
     }
 
     @Override
     public Header[] getAllHeaders() {
-        return super.getAllHeaders();
+        return null;
     }
 
     @Override
@@ -173,13 +160,25 @@ final class OptionsHttp11Response extend
 
     @Override
     public Iterator<Header> headerIterator() {
-        return super.headerIterator();
+        return Collections.emptyIterator();
     }
 
     @Override
     public Iterator<Header> headerIterator(final String name) {
-        return super.headerIterator(name);
+        return Collections.emptyIterator();
     }
 
+    @Override
+    public HttpEntity getEntity() {
+        return null;
+    }
+
+    @Override
+    public void setEntity(final HttpEntity entity) {
+    }
+
+    @Override
+    public void close() throws IOException {
+    }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java Tue Dec 27 19:48:07 2016
@@ -28,32 +28,34 @@ package org.apache.hc.client5.http.impl.
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.hc.client5.http.cache.HeaderConstants;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.ClientProtocolException;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HeaderElements;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.entity.AbstractHttpEntity;
-import org.apache.hc.core5.http.entity.ContentType;
+import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.apache.hc.core5.http.message.BasicHeader;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.apache.hc.core5.http.message.BasicStatusLine;
+import org.apache.hc.core5.http.message.MessageSupport;
 
 /**
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class RequestProtocolCompliance {
     private final boolean weakETagOnPutDeleteAllowed;
 
@@ -107,7 +109,7 @@ class RequestProtocolCompliance {
      * @param request the request to check for compliance
      * @throws ClientProtocolException when we have trouble making the request compliant
      */
-    public void makeRequestCompliant(final HttpRequestWrapper request)
+    public void makeRequestCompliant(final RoutedHttpRequest request)
         throws ClientProtocolException {
 
         if (requestMustNotHaveEntity(request)) {
@@ -119,23 +121,22 @@ class RequestProtocolCompliance {
         decrementOPTIONSMaxForwardsIfGreaterThen0(request);
         stripOtherFreshnessDirectivesWithNoCache(request);
 
-        if (requestVersionIsTooLow(request)
-                || requestMinorVersionIsTooHighMajorVersionsMatch(request)) {
-            request.setProtocolVersion(HttpVersion.HTTP_1_1);
+        if (requestVersionIsTooLow(request) || requestMinorVersionIsTooHighMajorVersionsMatch(request)) {
+            request.setVersion(HttpVersion.HTTP_1_1);
         }
     }
 
     private void stripOtherFreshnessDirectivesWithNoCache(final HttpRequest request) {
         final List<HeaderElement> outElts = new ArrayList<>();
         boolean shouldStrip = false;
-        for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
-            for(final HeaderElement elt : h.getElements()) {
-                if (!disallowedWithNoCache.contains(elt.getName())) {
-                    outElts.add(elt);
-                }
-                if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elt.getName())) {
-                    shouldStrip = true;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL);
+        while (it.hasNext()) {
+            final HeaderElement elt = it.next();
+            if (!disallowedWithNoCache.contains(elt.getName())) {
+                outElts.add(elt);
+            }
+            if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elt.getName())) {
+                shouldStrip = true;
             }
         }
         if (!shouldStrip) {
@@ -160,11 +161,11 @@ class RequestProtocolCompliance {
     }
 
     private boolean requestMustNotHaveEntity(final HttpRequest request) {
-        return HeaderConstants.TRACE_METHOD.equals(request.getRequestLine().getMethod());
+        return HeaderConstants.TRACE_METHOD.equals(request.getMethod());
     }
 
     private void decrementOPTIONSMaxForwardsIfGreaterThen0(final HttpRequest request) {
-        if (!HeaderConstants.OPTIONS_METHOD.equals(request.getRequestLine().getMethod())) {
+        if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
             return;
         }
 
@@ -179,22 +180,22 @@ class RequestProtocolCompliance {
         request.setHeader(HeaderConstants.MAX_FORWARDS, Integer.toString(currentMaxForwards - 1));
     }
 
-    private void verifyOPTIONSRequestWithBodyHasContentType(final HttpRequest request) {
-        if (!HeaderConstants.OPTIONS_METHOD.equals(request.getRequestLine().getMethod())) {
+    private void verifyOPTIONSRequestWithBodyHasContentType(final RoutedHttpRequest request) {
+        if (!HeaderConstants.OPTIONS_METHOD.equals(request.getMethod())) {
             return;
         }
 
         addContentTypeHeaderIfMissing(request);
     }
 
-    private void addContentTypeHeaderIfMissing(final HttpRequest request) {
+    private void addContentTypeHeaderIfMissing(final RoutedHttpRequest request) {
         final HttpEntity entity = request.getEntity();
         if (entity != null && entity.getContentType() == null) {
             ((AbstractHttpEntity) entity).setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
         }
     }
 
-    private void verifyRequestWithExpectContinueFlagHas100continueHeader(final HttpRequest request) {
+    private void verifyRequestWithExpectContinueFlagHas100continueHeader(final RoutedHttpRequest request) {
         if (request.containsHeader(HttpHeaders.EXPECT) && request.getEntity() != null) {
             add100ContinueHeaderIfMissing(request);
         } else {
@@ -209,7 +210,7 @@ class RequestProtocolCompliance {
         List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList<>();
 
         for (final Header h : expectHeaders) {
-            for (final HeaderElement elt : h.getElements()) {
+            for (final HeaderElement elt : MessageSupport.parse(h)) {
                 if (!(HeaderElements.CONTINUE.equalsIgnoreCase(elt.getName()))) {
                     expectElementsThatAreNot100Continue.add(elt);
                 } else {
@@ -233,11 +234,11 @@ class RequestProtocolCompliance {
     private void add100ContinueHeaderIfMissing(final HttpRequest request) {
         boolean hasHeader = false;
 
-        for (final Header h : request.getHeaders(HttpHeaders.EXPECT)) {
-            for (final HeaderElement elt : h.getElements()) {
-                if (HeaderElements.CONTINUE.equalsIgnoreCase(elt.getName())) {
-                    hasHeader = true;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(request, HttpHeaders.EXPECT);
+        while (it.hasNext()) {
+            final HeaderElement elt = it.next();
+            if (HeaderElements.CONTINUE.equalsIgnoreCase(elt.getName())) {
+                hasHeader = true;
             }
         }
 
@@ -247,7 +248,7 @@ class RequestProtocolCompliance {
     }
 
     protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpRequest request) {
-        final ProtocolVersion requestProtocol = request.getProtocolVersion();
+        final ProtocolVersion requestProtocol = request.getVersion();
         if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) {
             return false;
         }
@@ -260,7 +261,7 @@ class RequestProtocolCompliance {
     }
 
     protected boolean requestVersionIsTooLow(final HttpRequest request) {
-        return request.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) < 0;
+        return request.getVersion().compareToVersion(HttpVersion.HTTP_1_1) < 0;
     }
 
     /**
@@ -268,27 +269,24 @@ class RequestProtocolCompliance {
      * that a problem occured.
      *
      * @param errorCheck What type of error should I get
-     * @return The {@link HttpResponse} that is the error generated
+     * @return The {@link ClassicHttpResponse} that is the error generated
      */
-    public HttpResponse getErrorForRequest(final RequestProtocolError errorCheck) {
+    public ClassicHttpResponse getErrorForRequest(final RequestProtocolError errorCheck) {
         switch (errorCheck) {
             case BODY_BUT_NO_LENGTH_ERROR:
-                return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1,
-                        HttpStatus.SC_LENGTH_REQUIRED, ""));
+                return new BasicClassicHttpResponse(HttpStatus.SC_LENGTH_REQUIRED, "");
 
             case WEAK_ETAG_AND_RANGE_ERROR:
-                return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1,
-                        HttpStatus.SC_BAD_REQUEST, "Weak eTag not compatible with byte range"));
+                return new BasicClassicHttpResponse(HttpStatus.SC_BAD_REQUEST,
+                        "Weak eTag not compatible with byte range");
 
             case WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR:
-                return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1,
-                        HttpStatus.SC_BAD_REQUEST,
-                        "Weak eTag not compatible with PUT or DELETE requests"));
+                return new BasicClassicHttpResponse(HttpStatus.SC_BAD_REQUEST,
+                        "Weak eTag not compatible with PUT or DELETE requests");
 
             case NO_CACHE_DIRECTIVE_WITH_FIELD_NAME:
-                return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1,
-                        HttpStatus.SC_BAD_REQUEST,
-                        "No-Cache directive MUST NOT include a field name"));
+                return new BasicClassicHttpResponse(HttpStatus.SC_BAD_REQUEST,
+                        "No-Cache directive MUST NOT include a field name");
 
             default:
                 throw new IllegalStateException(
@@ -299,7 +297,7 @@ class RequestProtocolCompliance {
 
     private RequestProtocolError requestHasWeakETagAndRange(final HttpRequest request) {
         // TODO: Should these be looking at all the headers marked as Range?
-        final String method = request.getRequestLine().getMethod();
+        final String method = request.getMethod();
         if (!(HeaderConstants.GET_METHOD.equals(method))) {
             return null;
         }
@@ -325,9 +323,8 @@ class RequestProtocolCompliance {
     private RequestProtocolError requestHasWeekETagForPUTOrDELETEIfMatch(final HttpRequest request) {
         // TODO: Should these be looking at all the headers marked as If-Match/If-None-Match?
 
-        final String method = request.getRequestLine().getMethod();
-        if (!(HeaderConstants.PUT_METHOD.equals(method) || HeaderConstants.DELETE_METHOD
-                .equals(method))) {
+        final String method = request.getMethod();
+        if (!(HeaderConstants.PUT_METHOD.equals(method) || HeaderConstants.DELETE_METHOD.equals(method))) {
             return null;
         }
 
@@ -353,12 +350,11 @@ class RequestProtocolCompliance {
     }
 
     private RequestProtocolError requestContainsNoCacheDirectiveWithFieldName(final HttpRequest request) {
-        for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
-            for(final HeaderElement elt : h.getElements()) {
-                if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(elt.getName())
-                    && elt.getValue() != null) {
-                    return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(request, HeaderConstants.CACHE_CONTROL);
+        while (it.hasNext()) {
+            final HeaderElement elt = it.next();
+            if (HeaderConstants.CACHE_CONTROL_NO_CACHE.equalsIgnoreCase(elt.getName()) && elt.getValue() != null) {
+                return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
             }
         }
         return null;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResourceReference.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResourceReference.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResourceReference.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResourceReference.java Tue Dec 27 19:48:07 2016
@@ -31,10 +31,11 @@ import java.lang.ref.ReferenceQueue;
 
 import org.apache.hc.client5.http.cache.HttpCacheEntry;
 import org.apache.hc.client5.http.cache.Resource;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.util.Args;
 
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class ResourceReference extends PhantomReference<HttpCacheEntry> {
 
     private final Resource resource;

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseCachingPolicy.java Tue Dec 27 19:48:07 2016
@@ -29,13 +29,15 @@ package org.apache.hc.client5.http.impl.
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hc.client5.http.cache.HeaderConstants;
 import org.apache.hc.client5.http.utils.DateUtils;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpHeaders;
@@ -44,13 +46,15 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.message.MessageSupport;
 
 /**
  * Determines if an HttpResponse can be cached.
  *
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class ResponseCachingPolicy {
 
     private static final String[] AUTH_CACHEABLE_PARAMS = {
@@ -111,7 +115,7 @@ class ResponseCachingPolicy {
             return false;
         }
 
-        final int status = response.getStatusLine().getStatusCode();
+        final int status = response.getCode();
         if (cacheableStatuses.contains(status)) {
             // these response codes MAY be cached
             cacheable = true;
@@ -154,11 +158,11 @@ class ResponseCachingPolicy {
             return false;
         }
 
-        for (final Header varyHdr : response.getHeaders(HeaderConstants.VARY)) {
-            for (final HeaderElement elem : varyHdr.getElements()) {
-                if ("*".equals(elem.getName())) {
-                    return false;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(response, HeaderConstants.VARY);
+        while (it.hasNext()) {
+            final HeaderElement elem = it.next();
+            if ("*".equals(elem.getName())) {
+                return false;
             }
         }
 
@@ -189,27 +193,25 @@ class ResponseCachingPolicy {
     }
 
     protected boolean isExplicitlyNonCacheable(final HttpResponse response) {
-        final Header[] cacheControlHeaders = response.getHeaders(HeaderConstants.CACHE_CONTROL);
-        for (final Header header : cacheControlHeaders) {
-            for (final HeaderElement elem : header.getElements()) {
-                if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName())
-                        || HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName())
-                        || (sharedCache && HeaderConstants.PRIVATE.equals(elem.getName()))) {
-                    return true;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(response, HeaderConstants.CACHE_CONTROL);
+        while (it.hasNext()) {
+            final HeaderElement elem = it.next();
+            if (HeaderConstants.CACHE_CONTROL_NO_STORE.equals(elem.getName())
+                    || HeaderConstants.CACHE_CONTROL_NO_CACHE.equals(elem.getName())
+                    || (sharedCache && HeaderConstants.PRIVATE.equals(elem.getName()))) {
+                return true;
             }
         }
         return false;
     }
 
     protected boolean hasCacheControlParameterFrom(final HttpMessage msg, final String[] params) {
-        final Header[] cacheControlHeaders = msg.getHeaders(HeaderConstants.CACHE_CONTROL);
-        for (final Header header : cacheControlHeaders) {
-            for (final HeaderElement elem : header.getElements()) {
-                for (final String param : params) {
-                    if (param.equalsIgnoreCase(elem.getName())) {
-                        return true;
-                    }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(msg, HeaderConstants.CACHE_CONTROL);
+        while (it.hasNext()) {
+            final HeaderElement elem = it.next();
+            for (final String param : params) {
+                if (param.equalsIgnoreCase(elem.getName())) {
+                    return true;
                 }
             }
         }
@@ -247,7 +249,7 @@ class ResponseCachingPolicy {
             return false;
         }
 
-        if (request.getRequestLine().getUri().contains("?")) {
+        if (request.getRequestUri().contains("?")) {
             if (neverCache1_0ResponsesWithQueryString && from1_0Origin(response)) {
                 log.debug("Response was not cacheable as it had a query string.");
                 return false;
@@ -269,7 +271,7 @@ class ResponseCachingPolicy {
             }
         }
 
-        final String method = request.getRequestLine().getMethod();
+        final String method = request.getMethod();
         return isResponseCacheable(method, response);
     }
 
@@ -292,22 +294,23 @@ class ResponseCachingPolicy {
     }
 
     private boolean from1_0Origin(final HttpResponse response) {
-        final Header via = response.getFirstHeader(HeaderConstants.VIA);
-        if (via != null) {
-            for(final HeaderElement elt : via.getElements()) {
-                final String proto = elt.toString().split("\\s")[0];
-                if (proto.contains("/")) {
-                    return proto.equals("HTTP/1.0");
-                } else {
-                    return proto.equals("1.0");
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(response, HeaderConstants.VIA);
+        while (it.hasNext()) {
+            final HeaderElement elt = it.next();
+            final String proto = elt.toString().split("\\s")[0];
+            if (proto.contains("/")) {
+                return proto.equals("HTTP/1.0");
+            } else {
+                return proto.equals("1.0");
             }
         }
-        return HttpVersion.HTTP_1_0.equals(response.getProtocolVersion());
+        final ProtocolVersion version = response.getVersion() != null ? response.getVersion() : HttpVersion.DEFAULT;
+        return HttpVersion.HTTP_1_0.equals(version);
     }
 
     private boolean requestProtocolGreaterThanAccepted(final HttpRequest req) {
-        return req.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) > 0;
+        final ProtocolVersion version = req.getVersion() != null ? req.getVersion() : HttpVersion.DEFAULT;
+        return version.compareToVersion(HttpVersion.HTTP_1_1) > 0;
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ResponseProtocolCompliance.java Tue Dec 27 19:48:07 2016
@@ -32,10 +32,12 @@ import java.util.Date;
 import java.util.List;
 
 import org.apache.hc.client5.http.cache.HeaderConstants;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.ClientProtocolException;
 import org.apache.hc.client5.http.utils.DateUtils;
-import org.apache.hc.core5.annotation.Immutable;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HeaderElements;
@@ -45,12 +47,14 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.hc.core5.http.message.MessageSupport;
 
 /**
  * @since 4.1
  */
-@Immutable
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
 class ResponseProtocolCompliance {
 
     private static final String UNEXPECTED_100_CONTINUE = "The incoming request did not contain a "
@@ -66,7 +70,7 @@ class ResponseProtocolCompliance {
      * @param response The {@link HttpResponse} from the origin server
      * @throws IOException Bad things happened
      */
-    public void ensureProtocolCompliance(final HttpRequestWrapper request, final HttpResponse response)
+    public void ensureProtocolCompliance(final RoutedHttpRequest request, final ClassicHttpResponse response)
             throws IOException {
         if (backendResponseMustNotHaveBody(request, response)) {
             consumeBody(response);
@@ -90,7 +94,7 @@ class ResponseProtocolCompliance {
         warningsWithNonMatchingWarnDatesAreRemoved(response);
     }
 
-    private void consumeBody(final HttpResponse response) throws IOException {
+    private void consumeBody(final ClassicHttpResponse response) throws IOException {
         final HttpEntity body = response.getEntity();
         if (body != null) {
             IOUtils.consume(body);
@@ -140,7 +144,7 @@ class ResponseProtocolCompliance {
         for (final Header h : hdrs) {
             final StringBuilder buf = new StringBuilder();
             boolean first = true;
-            for (final HeaderElement elt : h.getElements()) {
+            for (final HeaderElement elt : MessageSupport.parse(h)) {
                 if ("identity".equalsIgnoreCase(elt.getName())) {
                     modified = true;
                 } else {
@@ -173,9 +177,9 @@ class ResponseProtocolCompliance {
     }
 
     private void ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(final HttpRequest request,
-            final HttpResponse response) throws IOException {
+            final ClassicHttpResponse response) throws IOException {
         if (request.getFirstHeader(HeaderConstants.RANGE) != null
-                || response.getStatusLine().getStatusCode() != HttpStatus.SC_PARTIAL_CONTENT) {
+                || response.getCode() != HttpStatus.SC_PARTIAL_CONTENT) {
             return;
         }
 
@@ -185,11 +189,11 @@ class ResponseProtocolCompliance {
 
     private void ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(final HttpRequest request,
             final HttpResponse response) {
-        if (!request.getRequestLine().getMethod().equalsIgnoreCase(HeaderConstants.OPTIONS_METHOD)) {
+        if (!request.getMethod().equalsIgnoreCase(HeaderConstants.OPTIONS_METHOD)) {
             return;
         }
 
-        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+        if (response.getCode() != HttpStatus.SC_OK) {
             return;
         }
 
@@ -203,7 +207,7 @@ class ResponseProtocolCompliance {
                 "Content-Language", HttpHeaders.CONTENT_LENGTH, "Content-MD5",
                 "Content-Range", HttpHeaders.CONTENT_TYPE, HeaderConstants.LAST_MODIFIED
         };
-        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
+        if (response.getCode() == HttpStatus.SC_NOT_MODIFIED) {
             for(final String hdr : disallowedEntityHeaders) {
                 response.removeHeaders(hdr);
             }
@@ -211,15 +215,15 @@ class ResponseProtocolCompliance {
     }
 
     private boolean backendResponseMustNotHaveBody(final HttpRequest request, final HttpResponse backendResponse) {
-        return HeaderConstants.HEAD_METHOD.equals(request.getRequestLine().getMethod())
-                || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT
-                || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_RESET_CONTENT
-                || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED;
+        return HeaderConstants.HEAD_METHOD.equals(request.getMethod())
+                || backendResponse.getCode() == HttpStatus.SC_NO_CONTENT
+                || backendResponse.getCode() == HttpStatus.SC_RESET_CONTENT
+                || backendResponse.getCode() == HttpStatus.SC_NOT_MODIFIED;
     }
 
-    private void requestDidNotExpect100ContinueButResponseIsOne(final HttpRequestWrapper request,
-            final HttpResponse response) throws IOException {
-        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) {
+    private void requestDidNotExpect100ContinueButResponseIsOne(final RoutedHttpRequest request,
+            final ClassicHttpResponse response) throws IOException {
+        if (response.getCode() != HttpStatus.SC_CONTINUE) {
             return;
         }
 
@@ -232,10 +236,11 @@ class ResponseProtocolCompliance {
         throw new ClientProtocolException(UNEXPECTED_100_CONTINUE);
     }
 
-    private void transferEncodingIsNotReturnedTo1_0Client(final HttpRequestWrapper request,
+    private void transferEncodingIsNotReturnedTo1_0Client(final RoutedHttpRequest request,
             final HttpResponse response) {
         final HttpRequest originalRequest = request.getOriginal();
-        if (originalRequest.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
+        final ProtocolVersion version = originalRequest.getVersion() != null ? originalRequest.getVersion() : HttpVersion.DEFAULT;
+        if (version.compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
             return;
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/SizeLimitedResponseReader.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/SizeLimitedResponseReader.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/SizeLimitedResponseReader.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/SizeLimitedResponseReader.java Tue Dec 27 19:48:07 2016
@@ -28,28 +28,24 @@ package org.apache.hc.client5.http.impl.
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.Proxy;
 
 import org.apache.hc.client5.http.cache.InputLimit;
 import org.apache.hc.client5.http.cache.Resource;
 import org.apache.hc.client5.http.cache.ResourceFactory;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
-import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 
 /**
  * @since 4.1
  */
-@NotThreadSafe
 class SizeLimitedResponseReader {
 
     private final ResourceFactory resourceFactory;
     private final long maxResponseSizeBytes;
     private final HttpRequest request;
-    private final CloseableHttpResponse response;
+    private final ClassicHttpResponse response;
 
     private InputStream instream;
     private InputLimit limit;
@@ -57,14 +53,14 @@ class SizeLimitedResponseReader {
     private boolean consumed;
 
     /**
-     * Create an {@link HttpResponse} that is limited in size, this allows for checking
+     * Create an {@link ClassicHttpResponse} that is limited in size, this allows for checking
      * the size of objects that will be stored in the cache.
      */
     public SizeLimitedResponseReader(
             final ResourceFactory resourceFactory,
             final long maxResponseSizeBytes,
             final HttpRequest request,
-            final CloseableHttpResponse response) {
+            final ClassicHttpResponse response) {
         super();
         this.resourceFactory = resourceFactory;
         this.maxResponseSizeBytes = maxResponseSizeBytes;
@@ -100,7 +96,7 @@ class SizeLimitedResponseReader {
         if (entity == null) {
             return;
         }
-        final String uri = request.getRequestLine().getUri();
+        final String uri = request.getRequestUri();
         instream = entity.getContent();
         try {
             resource = resourceFactory.generate(uri, instream, limit);
@@ -121,9 +117,19 @@ class SizeLimitedResponseReader {
         return resource;
     }
 
-    CloseableHttpResponse getReconstructedResponse() throws IOException {
+    ClassicHttpResponse getReconstructedResponse() throws IOException {
         ensureConsumed();
-        final HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine());
+        final ClassicHttpResponse reconstructed = new BasicClassicHttpResponse(response.getCode()) {
+
+            @Override
+            public void close() throws IOException {
+                try {
+                    super.close();
+                } finally {
+                    response.close();
+                }
+            }
+        };
         reconstructed.setHeaders(response.getAllHeaders());
 
         final CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
@@ -134,17 +140,7 @@ class SizeLimitedResponseReader {
             combinedEntity.setChunked(entity.isChunked());
         }
         reconstructed.setEntity(combinedEntity);
-        return (CloseableHttpResponse) Proxy.newProxyInstance(
-                ResponseProxyHandler.class.getClassLoader(),
-                new Class<?>[] { CloseableHttpResponse.class },
-                new ResponseProxyHandler(reconstructed) {
-
-                    @Override
-                    public void close() throws IOException {
-                        response.close();
-                    }
-
-                });
+        return reconstructed;
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/cache/TestHttpCacheEntry.java Tue Dec 27 19:48:07 2016
@@ -42,10 +42,7 @@ import java.util.Map;
 import org.apache.hc.client5.http.utils.DateUtils;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.StatusLine;
 import org.apache.hc.core5.http.message.BasicHeader;
-import org.apache.hc.core5.http.message.BasicStatusLine;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -55,7 +52,6 @@ public class TestHttpCacheEntry {
     private Date elevenSecondsAgo;
     private Date nineSecondsAgo;
     private Resource mockResource;
-    private StatusLine statusLine;
     private HttpCacheEntry entry;
 
     @Before
@@ -63,14 +59,11 @@ public class TestHttpCacheEntry {
         now = new Date();
         elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
         nineSecondsAgo = new Date(now.getTime() - 9 * 1000L);
-        statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_OK, "OK");
         mockResource = mock(Resource.class);
     }
 
     private HttpCacheEntry makeEntry(final Header[] headers) {
-        return new HttpCacheEntry(elevenSecondsAgo, nineSecondsAgo,
-                statusLine, headers, mockResource, HeaderConstants.GET_METHOD);
+        return new HttpCacheEntry(elevenSecondsAgo, nineSecondsAgo, HttpStatus.SC_OK, headers, mockResource);
     }
 
     @Test
@@ -147,8 +140,7 @@ public class TestHttpCacheEntry {
     @Test
     public void mustProvideRequestDate() {
         try {
-            new HttpCacheEntry(null, new Date(), statusLine,
-                    new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+            new HttpCacheEntry(null, new Date(), HttpStatus.SC_OK, new Header[]{}, mockResource);
             fail("Should have thrown exception");
         } catch (final IllegalArgumentException expected) {
         }
@@ -158,19 +150,7 @@ public class TestHttpCacheEntry {
     @Test
     public void mustProvideResponseDate() {
         try {
-            new HttpCacheEntry(new Date(), null, statusLine,
-                    new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
-            fail("Should have thrown exception");
-        } catch (final IllegalArgumentException expected) {
-        }
-    }
-
-    @SuppressWarnings("unused")
-    @Test
-    public void mustProvideStatusLine() {
-        try {
-            new HttpCacheEntry(new Date(), new Date(), null,
-                    new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+            new HttpCacheEntry(new Date(), null, HttpStatus.SC_OK, new Header[]{}, mockResource);
             fail("Should have thrown exception");
         } catch (final IllegalArgumentException expected) {
         }
@@ -180,62 +160,35 @@ public class TestHttpCacheEntry {
     @Test
     public void mustProvideResponseHeaders() {
         try {
-            new HttpCacheEntry(new Date(), new Date(), statusLine,
-                    null, mockResource, HeaderConstants.GET_METHOD);
+            new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, null, mockResource);
             fail("Should have thrown exception");
         } catch (final IllegalArgumentException expected) {
         }
     }
 
     @Test
-    public void canRetrieveOriginalStatusLine() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
-        assertSame(statusLine, entry.getStatusLine());
-    }
-
-    @Test
-    public void protocolVersionComesFromOriginalStatusLine() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
-        assertSame(statusLine.getProtocolVersion(),
-                entry.getProtocolVersion());
-    }
-
-    @Test
-    public void reasonPhraseComesFromOriginalStatusLine() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
-        assertSame(statusLine.getReasonPhrase(), entry.getReasonPhrase());
-    }
-
-    @Test
     public void statusCodeComesFromOriginalStatusLine() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
-        assertEquals(statusLine.getStatusCode(), entry.getStatusCode());
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, new Header[]{}, mockResource);
+        assertEquals(HttpStatus.SC_OK, entry.getStatus());
     }
 
     @Test
     public void canGetOriginalRequestDate() {
         final Date requestDate = new Date();
-        entry = new HttpCacheEntry(requestDate, new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(requestDate, new Date(), HttpStatus.SC_OK, new Header[]{}, mockResource);
         assertSame(requestDate, entry.getRequestDate());
     }
 
     @Test
     public void canGetOriginalResponseDate() {
         final Date responseDate = new Date();
-        entry = new HttpCacheEntry(new Date(), responseDate, statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), responseDate, HttpStatus.SC_OK, new Header[]{}, mockResource);
         assertSame(responseDate, entry.getResponseDate());
     }
 
     @Test
     public void canGetOriginalResource() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, new Header[]{}, mockResource);
         assertSame(mockResource, entry.getResource());
     }
 
@@ -245,8 +198,7 @@ public class TestHttpCacheEntry {
                 new BasicHeader("Server", "MockServer/1.0"),
                 new BasicHeader("Date", DateUtils.formatDate(now))
         };
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                headers, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, headers, mockResource);
         final Header[] result = entry.getAllHeaders();
         assertEquals(headers.length, result.length);
         for(int i=0; i<headers.length; i++) {
@@ -257,16 +209,15 @@ public class TestHttpCacheEntry {
     @SuppressWarnings("unused")
     @Test
     public void canConstructWithoutVariants() {
-        new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+        new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK, new Header[]{}, mockResource);
     }
 
     @SuppressWarnings("unused")
     @Test
     public void canProvideVariantMap() {
-        new HttpCacheEntry(new Date(), new Date(), statusLine,
+        new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
                 new Header[]{}, mockResource,
-                new HashMap<String,String>(), HeaderConstants.GET_METHOD);
+                new HashMap<String,String>());
     }
 
     @Test
@@ -274,9 +225,9 @@ public class TestHttpCacheEntry {
         final Map<String,String> variantMap = new HashMap<>();
         variantMap.put("A","B");
         variantMap.put("C","D");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
                 new Header[]{}, mockResource,
-                variantMap, HeaderConstants.GET_METHOD);
+                variantMap);
         final Map<String,String> result = entry.getVariantMap();
         assertEquals(2, result.size());
         assertEquals("B", result.get("A"));
@@ -288,9 +239,9 @@ public class TestHttpCacheEntry {
         final Map<String,String> variantMap = new HashMap<>();
         variantMap.put("A","B");
         variantMap.put("C","D");
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
                 new Header[]{}, mockResource,
-                variantMap, HeaderConstants.GET_METHOD);
+                variantMap);
         final Map<String,String> result = entry.getVariantMap();
         try {
             result.remove("A");
@@ -306,8 +257,8 @@ public class TestHttpCacheEntry {
 
     @Test
     public void canConvertToString() {
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                new Header[]{}, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
+                new Header[]{}, mockResource);
         assertNotNull(entry.toString());
         assertFalse("".equals(entry.toString()));
     }
@@ -315,16 +266,16 @@ public class TestHttpCacheEntry {
     @Test
     public void testMissingDateHeaderIsIgnored() {
         final Header[] headers = new Header[] {};
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                                   headers, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
+                                   headers, mockResource);
         assertNull(entry.getDate());
     }
 
     @Test
     public void testMalformedDateHeaderIsIgnored() {
         final Header[] headers = new Header[] { new BasicHeader("Date", "asdf") };
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                                   headers, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
+                                   headers, mockResource);
         assertNull(entry.getDate());
     }
 
@@ -334,8 +285,8 @@ public class TestHttpCacheEntry {
         // round down to nearest second to make comparison easier
         final Date date = new Date(nowMs - (nowMs % 1000L));
         final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatDate(date)) };
-        entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
-                                   headers, mockResource, HeaderConstants.GET_METHOD);
+        entry = new HttpCacheEntry(new Date(), new Date(), HttpStatus.SC_OK,
+                                   headers, mockResource);
         final Date dateHeaderValue = entry.getDate();
         assertNotNull(dateHeaderValue);
         assertEquals(date.getTime(), dateHeaderValue.getTime());

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java Tue Dec 27 19:48:07 2016
@@ -31,16 +31,15 @@ import java.util.HashMap;
 import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.cache.HttpCacheContext;
 import org.apache.hc.client5.http.impl.sync.ClientExecChain;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
 import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.message.BasicHttpRequest;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.easymock.EasyMock;
 import org.easymock.IExpectationSetters;
 import org.junit.Before;
@@ -55,14 +54,14 @@ public abstract class AbstractProtocolTe
     protected HttpEntity body;
     protected ClientExecChain mockBackend;
     protected HttpCache mockCache;
-    protected HttpRequestWrapper request;
+    protected RoutedHttpRequest request;
     protected HttpCacheContext context;
-    protected CloseableHttpResponse originResponse;
+    protected ClassicHttpResponse originResponse;
     protected CacheConfig config;
     protected ClientExecChain impl;
     protected HttpCache cache;
 
-    public static HttpRequestWrapper eqRequest(final HttpRequestWrapper in) {
+    public static RoutedHttpRequest eqRequest(final RoutedHttpRequest in) {
         EasyMock.reportMatcher(new RequestEquivalent(in));
         return null;
     }
@@ -72,7 +71,7 @@ public abstract class AbstractProtocolTe
         return null;
     }
 
-    public static CloseableHttpResponse eqCloseableResponse(final CloseableHttpResponse in) {
+    public static ClassicHttpResponse eqCloseableResponse(final ClassicHttpResponse in) {
         EasyMock.reportMatcher(new ResponseEquivalent(in));
         return null;
     }
@@ -85,12 +84,11 @@ public abstract class AbstractProtocolTe
 
         body = HttpTestUtils.makeBody(entityLength);
 
-        request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1), host);
+        request = RoutedHttpRequest.adapt(new BasicClassicHttpRequest("GET", "/foo"), route);
 
         context = HttpCacheContext.create();
-        context.setTargetHost(host);
 
-        originResponse = Proxies.enhanceResponse(HttpTestUtils.make200Response());
+        originResponse = HttpTestUtils.make200Response();
 
         config = CacheConfig.custom()
             .setMaxCacheEntries(MAX_ENTRIES)
@@ -122,23 +120,21 @@ public abstract class AbstractProtocolTe
         EasyMock.verify(mockCache);
     }
 
-    protected IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequest() throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.isA(HttpRequestWrapper.class),
+    protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequest() throws Exception {
+        final ClassicHttpResponse resp = mockBackend.execute(
+                EasyMock.isA(RoutedHttpRequest.class),
                 EasyMock.isA(HttpClientContext.class),
                 EasyMock.<HttpExecutionAware>isNull());
         return EasyMock.expect(resp);
     }
 
-    protected IExpectationSetters<CloseableHttpResponse> backendExpectsAnyRequestAndReturn(
-            final HttpResponse reponse) throws Exception {
-        final CloseableHttpResponse resp = mockBackend.execute(
-                EasyMock.isA(HttpRoute.class),
-                EasyMock.isA(HttpRequestWrapper.class),
+    protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequestAndReturn(
+            final ClassicHttpResponse response) throws Exception {
+        final ClassicHttpResponse resp = mockBackend.execute(
+                EasyMock.isA(RoutedHttpRequest.class),
                 EasyMock.isA(HttpClientContext.class),
                 EasyMock.<HttpExecutionAware>isNull());
-        return EasyMock.expect(resp).andReturn(Proxies.enhanceResponse(reponse));
+        return EasyMock.expect(resp).andReturn(response);
     }
 
     protected void emptyMockCacheExpectsNoPuts() throws Exception {

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/DummyBackend.java Tue Dec 27 19:48:07 2016
@@ -28,26 +28,24 @@ package org.apache.hc.client5.http.impl.
 
 import java.io.IOException;
 
-import org.apache.hc.client5.http.HttpRoute;
 import org.apache.hc.client5.http.impl.sync.ClientExecChain;
-import org.apache.hc.client5.http.methods.CloseableHttpResponse;
 import org.apache.hc.client5.http.methods.HttpExecutionAware;
-import org.apache.hc.client5.http.methods.HttpRequestWrapper;
+import org.apache.hc.client5.http.methods.RoutedHttpRequest;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
-import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 
 public class DummyBackend implements ClientExecChain {
 
-    private HttpRequest request;
-    private HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP",1,1), HttpStatus.SC_OK, "OK");
+    private ClassicHttpRequest request;
+    private ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
     private int executions = 0;
 
-    public void setResponse(final HttpResponse resp) {
+    public void setResponse(final ClassicHttpResponse resp) {
         response = resp;
     }
 
@@ -56,14 +54,13 @@ public class DummyBackend implements Cli
     }
 
     @Override
-    public CloseableHttpResponse execute(
-            final HttpRoute route,
-            final HttpRequestWrapper request,
+    public ClassicHttpResponse execute(
+            final RoutedHttpRequest request,
             final HttpClientContext clientContext,
             final HttpExecutionAware execAware) throws IOException, HttpException {
         this.request = request;
         executions++;
-        return Proxies.enhanceResponse(response);
+        return response;
     }
 
     public int getExecutions() {

Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java?rev=1776187&r1=1776186&r2=1776187&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpTestUtils.java Tue Dec 27 19:48:07 2016
@@ -29,27 +29,30 @@ package org.apache.hc.client5.http.impl.
 import java.io.InputStream;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Random;
 
-import org.apache.hc.client5.http.cache.HeaderConstants;
 import org.apache.hc.client5.http.cache.HttpCacheEntry;
 import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpEntity;
+import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpMessage;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
-import org.apache.hc.core5.http.RequestLine;
-import org.apache.hc.core5.http.StatusLine;
-import org.apache.hc.core5.http.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.apache.hc.core5.http.message.BasicHeader;
-import org.apache.hc.core5.http.message.BasicHttpRequest;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
-import org.apache.hc.core5.http.message.BasicStatusLine;
+import org.apache.hc.core5.http.message.MessageSupport;
+import org.apache.hc.core5.util.LangUtils;
 import org.junit.Assert;
 
 public class HttpTestUtils {
@@ -72,7 +75,7 @@ public class HttpTestUtils {
     private static final String[] MULTI_HEADERS = { "Accept", "Accept-Charset", "Accept-Encoding",
         "Accept-Language", "Allow", "Cache-Control", "Connection", "Content-Encoding",
         "Content-Language", "Expect", "Pragma", "Proxy-Authenticate", "TE", "Trailer",
-        "Transfer-Encoding", "Upgrade", "Via", "Warning", "WWW-Authenticate" };
+        "Transfer-Encoding", "Upgrade", "Via", HttpHeaders.WARNING, "WWW-Authenticate" };
     private static final String[] SINGLE_HEADERS = { "Accept-Ranges", "Age", "Authorization",
         "Content-Length", "Content-Location", "Content-MD5", "Content-Range", "Content-Type",
         "Date", "ETag", "Expires", "From", "Host", "If-Match", "If-Modified-Since",
@@ -151,32 +154,6 @@ public class HttpTestUtils {
     }
 
     /*
-     * Assert.asserts that the components of two status lines match in a way
-     * that differs only by hop-by-hop information. "2.1 Proxy Behavior ...We
-     * remind the reader that HTTP version numbers are hop-by-hop components of
-     * HTTP meesages, and are not end-to-end."
-     *
-     * @see http://www.ietf.org/rfc/rfc2145.txt
-     */
-    public static boolean semanticallyTransparent(final StatusLine l1, final StatusLine l2) {
-        return (l1.getReasonPhrase().equals(l2.getReasonPhrase()) && l1.getStatusCode() == l2
-                .getStatusCode());
-    }
-
-    /* Assert.asserts that the components of two status lines match. */
-    public static boolean equivalent(final StatusLine l1, final StatusLine l2) {
-        return (l1.getProtocolVersion().equals(l2.getProtocolVersion()) && semanticallyTransparent(
-                l1, l2));
-    }
-
-    /* Assert.asserts that the components of two request lines match. */
-    public static boolean equivalent(final RequestLine l1, final RequestLine l2) {
-        return (l1.getMethod().equals(l2.getMethod())
-                && l1.getProtocolVersion().equals(l2.getProtocolVersion()) && l1.getUri().equals(
-                        l2.getUri()));
-    }
-
-    /*
      * Retrieves the full header value by combining multiple headers and
      * separating with commas, canonicalizing whitespace along the way.
      *
@@ -225,31 +202,39 @@ public class HttpTestUtils {
      *
      * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec1.html#sec1.3
      */
-    public static boolean semanticallyTransparent(final HttpResponse r1, final HttpResponse r2)
-    throws Exception {
+    public static boolean semanticallyTransparent(
+            final ClassicHttpResponse r1, final ClassicHttpResponse r2) throws Exception {
         final boolean entitiesEquivalent = equivalent(r1.getEntity(), r2.getEntity());
         if (!entitiesEquivalent) {
             return false;
         }
-        final boolean statusLinesEquivalent = semanticallyTransparent(r1.getStatusLine(), r2.getStatusLine());
+        final boolean statusLinesEquivalent = LangUtils.equals(r1.getReasonPhrase(), r2.getReasonPhrase())
+                && r1.getCode() == r2.getCode();
         if (!statusLinesEquivalent) {
             return false;
         }
-        final boolean e2eHeadersEquivalentSubset = isEndToEndHeaderSubset(
-                r1, r2);
-        return e2eHeadersEquivalentSubset;
+        return isEndToEndHeaderSubset(r1, r2);
+    }
+
+    /* Assert.asserts that protocol versions equivalent. */
+    public static boolean equivalent(final ProtocolVersion v1, final ProtocolVersion v2) {
+        return LangUtils.equals(v1 != null ? v1 : HttpVersion.DEFAULT, v2 != null ? v2 : HttpVersion.DEFAULT );
     }
 
     /* Assert.asserts that two requests are morally equivalent. */
     public static boolean equivalent(final HttpRequest r1, final HttpRequest r2) {
-        return (equivalent(r1.getRequestLine(), r2.getRequestLine()) && isEndToEndHeaderSubset(r1,
-                r2));
+        return equivalent(r1.getVersion(), r2.getVersion()) &&
+                LangUtils.equals(r1.getMethod(), r2.getMethod()) &&
+                LangUtils.equals(r1.getRequestUri(), r2.getRequestUri()) &&
+                isEndToEndHeaderSubset(r1, r2);
     }
 
     /* Assert.asserts that two requests are morally equivalent. */
     public static boolean equivalent(final HttpResponse r1, final HttpResponse r2) {
-        return (equivalent(r1.getStatusLine(), r2.getStatusLine()) && isEndToEndHeaderSubset(r1,
-                r2));
+        return equivalent(r1.getVersion(), r2.getVersion()) &&
+                r1.getCode() == r2.getCode() &&
+                LangUtils.equals(r1.getReasonPhrase(), r2.getReasonPhrase()) &&
+                isEndToEndHeaderSubset(r1, r2);
     }
 
     public static byte[] getRandomBytes(final int nbytes) {
@@ -301,7 +286,7 @@ public class HttpTestUtils {
     public static HttpCacheEntry makeCacheEntry(final Date requestDate,
             final Date responseDate, final Header[] headers, final byte[] bytes,
             final Map<String,String> variantMap) {
-        return new HttpCacheEntry(requestDate, responseDate, makeStatusLine(), headers, new HeapResource(bytes), variantMap, HeaderConstants.GET_METHOD);
+        return new HttpCacheEntry(requestDate, responseDate, HttpStatus.SC_OK, headers, new HeapResource(bytes), variantMap);
     }
 
     public static HttpCacheEntry makeCacheEntry(final Header[] headers, final byte[] bytes) {
@@ -324,39 +309,31 @@ public class HttpTestUtils {
 
     public static HttpCacheEntry makeCacheEntryWithNoRequestMethodOrEntity(final Header[] headers) {
         final Date now = new Date();
-        return new HttpCacheEntry(now, now, makeStatusLine(), headers, null, null, null);
+        return new HttpCacheEntry(now, now, HttpStatus.SC_OK, headers, null, null);
     }
 
     public static HttpCacheEntry makeCacheEntryWithNoRequestMethod(final Header[] headers) {
         final Date now = new Date();
-        return new HttpCacheEntry(now, now, makeStatusLine(), headers, new HeapResource(getRandomBytes(128)), null, null);
+        return new HttpCacheEntry(now, now, HttpStatus.SC_OK, headers, new HeapResource(getRandomBytes(128)), null);
     }
 
     public static HttpCacheEntry make204CacheEntryWithNoRequestMethod(final Header[] headers) {
         final Date now = new Date();
-        return new HttpCacheEntry(now, now, make204StatusLine(), headers, null, null, HeaderConstants.HEAD_METHOD);
+        return new HttpCacheEntry(now, now, HttpStatus.SC_NO_CONTENT, headers, null, null);
     }
 
     public static HttpCacheEntry makeHeadCacheEntry(final Header[] headers) {
         final Date now = new Date();
-        return new HttpCacheEntry(now, now, makeStatusLine(), headers, null, null, HeaderConstants.HEAD_METHOD);
+        return new HttpCacheEntry(now, now, HttpStatus.SC_OK, headers, null, null);
     }
 
     public static HttpCacheEntry makeHeadCacheEntryWithNoRequestMethod(final Header[] headers) {
         final Date now = new Date();
-        return new HttpCacheEntry(now, now, makeStatusLine(), headers, null, null, null);
+        return new HttpCacheEntry(now, now, HttpStatus.SC_OK, headers, null, null);
     }
 
-    public static StatusLine makeStatusLine() {
-        return new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
-    }
-
-    public static StatusLine make204StatusLine() {
-        return new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "OK");
-    }
-
-    public static HttpResponse make200Response() {
-        final HttpResponse out = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+    public static ClassicHttpResponse make200Response() {
+        final ClassicHttpResponse out = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
         out.setHeader("Date", DateUtils.formatDate(new Date()));
         out.setHeader("Server", "MockOrigin/1.0");
         out.setHeader("Content-Length", "128");
@@ -364,39 +341,42 @@ public class HttpTestUtils {
         return out;
     }
 
-    public static final HttpResponse make200Response(final Date date, final String cacheControl) {
-        final HttpResponse response = HttpTestUtils.make200Response();
+    public static final ClassicHttpResponse make200Response(final Date date, final String cacheControl) {
+        final ClassicHttpResponse response = HttpTestUtils.make200Response();
         response.setHeader("Date", DateUtils.formatDate(date));
         response.setHeader("Cache-Control",cacheControl);
         response.setHeader("Etag","\"etag\"");
         return response;
     }
 
+    public static ClassicHttpResponse make304Response() {
+        return new BasicClassicHttpResponse(HttpStatus.SC_NOT_MODIFIED, "Not modified");
+    }
+
     public static final void assert110WarningFound(final HttpResponse response) {
         boolean found110Warning = false;
-        for(final Header h : response.getHeaders("Warning")) {
-            for(final HeaderElement elt : h.getElements()) {
-                final String[] parts = elt.getName().split("\\s");
-                if ("110".equals(parts[0])) {
-                    found110Warning = true;
-                    break;
-                }
+        final Iterator<HeaderElement> it = MessageSupport.iterate(response, HttpHeaders.WARNING);
+        while (it.hasNext()) {
+            final HeaderElement elt = it.next();
+            final String[] parts = elt.getName().split("\\s");
+            if ("110".equals(parts[0])) {
+                found110Warning = true;
+                break;
             }
         }
         Assert.assertTrue(found110Warning);
     }
 
-    public static HttpRequest makeDefaultRequest() {
-        return new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
+    public static ClassicHttpRequest makeDefaultRequest() {
+        return new BasicClassicHttpRequest("GET", "/");
     }
 
-    public static HttpRequest makeDefaultHEADRequest() {
-        return new BasicHttpRequest("HEAD","/",HttpVersion.HTTP_1_1);
+    public static ClassicHttpRequest makeDefaultHEADRequest() {
+        return new BasicClassicHttpRequest("HEAD", "/");
     }
 
-    public static HttpResponse make500Response() {
-        return new BasicHttpResponse(HttpVersion.HTTP_1_1,
-                HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
+    public static ClassicHttpResponse make500Response() {
+        return new BasicClassicHttpResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
     }
 
     public static Map<String, String> makeDefaultVariantMap(final String key, final String value) {



Mime
View raw message