hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793324 - in /httpcomponents/httpclient/trunk: httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/ httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ httpclient5/src/main/java/org/apache/hc/client5/http/proto...
Date Mon, 01 May 2017 13:04:26 GMT
Author: olegk
Date: Mon May  1 13:04:26 2017
New Revision: 1793324

URL: http://svn.apache.org/viewvc?rev=1793324&view=rev
Log:
Fixed automatic content compression in classic exec chain

Added:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
  (contents, props changed)
      - copied, changed from r1793320, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseContentEncoding.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
  (contents, props changed)
      - copied, changed from r1793320, httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseContentEncoding.java
Removed:
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestAcceptEncoding.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseContentEncoding.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestAcceptEncoding.java
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseContentEncoding.java
Modified:
    httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
    httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java

Modified: httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java?rev=1793324&r1=1793323&r2=1793324&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java
Mon May  1 13:04:26 2017
@@ -57,7 +57,6 @@ import org.apache.hc.core5.http.io.entit
 import org.apache.hc.core5.http.message.MessageSupport;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -65,7 +64,6 @@ import org.junit.Test;
  * require no intervention from the user of HttpClient, but we still want to let clients
do their
  * own thing if they so wish.
  */
-@Ignore(value = "Disabled until content coding is fixed")
 public class TestContentCodings extends LocalServerTestBase {
 
     /**

Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
(from r1793320, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseContentEncoding.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseContentEncoding.java&r1=1793320&r2=1793324&rev=1793324&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/ResponseContentEncoding.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
Mon May  1 13:04:26 2017
@@ -24,40 +24,49 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.client5.http.protocol;
+
+package org.apache.hc.client5.http.impl.sync;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Locale;
 import java.util.zip.GZIPInputStream;
 
 import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.entity.DecompressingEntity;
 import org.apache.hc.client5.http.entity.DeflateInputStream;
 import org.apache.hc.client5.http.entity.InputStreamFactory;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HeaderElement;
+import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpResponseInterceptor;
+import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.message.BasicHeaderValueParser;
 import org.apache.hc.core5.http.message.ParserCursor;
-import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.util.Args;
 
 /**
- * {@link HttpResponseInterceptor} responsible for processing Content-Encoding
- * responses.
+ * Request executor in the request execution chain that is responsible
+ * for automatic response content decompression.
  * <p>
- * Instances of this class are stateless and immutable, therefore threadsafe.
- *
- * @since 4.1
+ * Further responsibilities such as communication with the opposite
+ * endpoint is delegated to the next executor in the request execution
+ * chain.
  *
+ * @since 5.0
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class ResponseContentEncoding implements HttpResponseInterceptor {
+public final class ContentCompressionExec implements ExecChainHandler {
 
     private final static InputStreamFactory GZIP = new InputStreamFactory() {
 
@@ -76,34 +85,26 @@ public class ResponseContentEncoding imp
 
     };
 
+    private final List<String> acceptEncoding;
     private final Lookup<InputStreamFactory> decoderRegistry;
     private final boolean ignoreUnknown;
 
-    /**
-     * @since 4.5
-     */
-    public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry,
final boolean ignoreUnknown) {
+    public ContentCompressionExec(
+            final List<String> acceptEncoding,
+            final Lookup<InputStreamFactory> decoderRegistry,
+            final boolean ignoreUnknown) {
+        this.acceptEncoding = acceptEncoding != null ? acceptEncoding : Arrays.asList("gzip",
"x-gzip", "deflate");
         this.decoderRegistry = decoderRegistry != null ? decoderRegistry :
-            RegistryBuilder.<InputStreamFactory>create()
-                    .register("gzip", GZIP)
-                    .register("x-gzip", GZIP)
-                    .register("deflate", DEFLATE)
-                    .build();
+                RegistryBuilder.<InputStreamFactory>create()
+                        .register("gzip", GZIP)
+                        .register("x-gzip", GZIP)
+                        .register("deflate", DEFLATE)
+                        .build();
         this.ignoreUnknown = ignoreUnknown;
     }
 
-    /**
-     * @since 4.5
-     */
-    public ResponseContentEncoding(final boolean ignoreUnknown) {
-        this(null, ignoreUnknown);
-    }
-
-    /**
-     * @since 4.4
-     */
-    public ResponseContentEncoding(final Lookup<InputStreamFactory> decoderRegistry)
{
-        this(decoderRegistry, true);
+    public ContentCompressionExec(final boolean ignoreUnknown) {
+        this(null, null, ignoreUnknown);
     }
 
     /**
@@ -114,18 +115,30 @@ public class ResponseContentEncoding imp
      * <li>deflate - see {@link DeflateInputStream}</li>
      * </ul>
      */
-    public ResponseContentEncoding() {
-        this(null);
+    public ContentCompressionExec() {
+        this(null, null, true);
     }
 
+
     @Override
-    public void process(
-            final HttpResponse response,
-            final EntityDetails entity,
-            final HttpContext context) throws HttpException, IOException {
+    public ClassicHttpResponse execute(
+            final ClassicHttpRequest request,
+            final ExecChain.Scope scope,
+            final ExecChain chain) throws IOException, HttpException {
+        Args.notNull(request, "HTTP request");
+        Args.notNull(scope, "Scope");
 
-        final HttpClientContext clientContext = HttpClientContext.adapt(context);
+        final HttpClientContext clientContext = scope.clientContext;
         final RequestConfig requestConfig = clientContext.getRequestConfig();
+
+        /* Signal support for Accept-Encoding transfer encodings. */
+        if (!request.containsHeader(HttpHeaders.ACCEPT_ENCODING) && requestConfig.isContentCompressionEnabled())
{
+            request.addHeader(HttpHeaders.ACCEPT_ENCODING, acceptEncoding);
+        }
+
+        final ClassicHttpResponse response = chain.proceed(request, scope);
+
+        final HttpEntity entity = response.getEntity();
         // entity can be null in case of 304 Not Modified, 204 No Content or similar
         // check for zero length entity.
         if (requestConfig.isContentCompressionEnabled() && entity != null &&
entity.getContentLength() != 0) {
@@ -137,10 +150,10 @@ public class ResponseContentEncoding imp
                     final String codecname = codec.getName().toLowerCase(Locale.ROOT);
                     final InputStreamFactory decoderFactory = decoderRegistry.lookup(codecname);
                     if (decoderFactory != null) {
-//                        response.setEntity(new DecompressingEntity(response.getEntity(),
decoderFactory));
-//                        response.removeHeaders("Content-Length");
-//                        response.removeHeaders("Content-Encoding");
-//                        response.removeHeaders("Content-MD5");
+                        response.setEntity(new DecompressingEntity(response.getEntity(),
decoderFactory));
+                        response.removeHeaders(HttpHeaders.CONTENT_LENGTH);
+                        response.removeHeaders(HttpHeaders.CONTENT_ENCODING);
+                        response.removeHeaders(HttpHeaders.CONTENT_MD5);
                     } else {
                         if (!"identity".equals(codecname) && !ignoreUnknown) {
                             throw new HttpException("Unsupported Content-Encoding: " + codec.getName());
@@ -149,6 +162,7 @@ public class ResponseContentEncoding imp
                 }
             }
         }
+        return response;
     }
 
 }

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/ContentCompressionExec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java?rev=1793324&r1=1793323&r2=1793324&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/HttpClientBuilder.java
Mon May  1 13:04:26 2017
@@ -32,7 +32,7 @@ import java.io.IOException;
 import java.net.ProxySelector;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -71,13 +71,11 @@ import org.apache.hc.client5.http.impl.r
 import org.apache.hc.client5.http.io.HttpClientConnectionManager;
 import org.apache.hc.client5.http.protocol.AuthenticationStrategy;
 import org.apache.hc.client5.http.protocol.RedirectStrategy;
-import org.apache.hc.client5.http.protocol.RequestAcceptEncoding;
 import org.apache.hc.client5.http.protocol.RequestAddCookies;
 import org.apache.hc.client5.http.protocol.RequestAuthCache;
 import org.apache.hc.client5.http.protocol.RequestClientConnControl;
 import org.apache.hc.client5.http.protocol.RequestDefaultHeaders;
 import org.apache.hc.client5.http.protocol.RequestExpectContinue;
-import org.apache.hc.client5.http.protocol.ResponseContentEncoding;
 import org.apache.hc.client5.http.protocol.ResponseProcessCookies;
 import org.apache.hc.client5.http.protocol.UserTokenHandler;
 import org.apache.hc.client5.http.routing.HttpRoutePlanner;
@@ -95,6 +93,7 @@ import org.apache.hc.core5.http.HttpRequ
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpResponseInterceptor;
 import org.apache.hc.core5.http.config.Lookup;
+import org.apache.hc.core5.http.config.Registry;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
@@ -205,7 +204,7 @@ public class HttpClientBuilder {
     private ServiceUnavailableRetryStrategy serviceUnavailStrategy;
     private Lookup<AuthSchemeProvider> authSchemeRegistry;
     private Lookup<CookieSpecProvider> cookieSpecRegistry;
-    private Map<String, InputStreamFactory> contentDecoderMap;
+    private LinkedHashMap<String, InputStreamFactory> contentDecoderMap;
     private CookieStore cookieStore;
     private CredentialsProvider credentialsProvider;
     private String userAgent;
@@ -602,7 +601,7 @@ public class HttpClientBuilder {
      * to be used for automatic content decompression.
      */
     public final HttpClientBuilder setContentDecoderRegistry(
-            final Map<String, InputStreamFactory> contentDecoderMap) {
+            final LinkedHashMap<String, InputStreamFactory> contentDecoderMap) {
         this.contentDecoderMap = contentDecoderMap;
         return this;
     }
@@ -794,32 +793,12 @@ public class HttpClientBuilder {
         if (!cookieManagementDisabled) {
             b.add(new RequestAddCookies());
         }
-        if (!contentCompressionDisabled) {
-            if (contentDecoderMap != null) {
-                final List<String> encodings = new ArrayList<>(contentDecoderMap.keySet());
-                Collections.sort(encodings);
-                b.add(new RequestAcceptEncoding(encodings));
-            } else {
-                b.add(new RequestAcceptEncoding());
-            }
-        }
         if (!authCachingDisabled) {
             b.add(new RequestAuthCache());
         }
         if (!cookieManagementDisabled) {
             b.add(new ResponseProcessCookies());
         }
-        if (!contentCompressionDisabled) {
-            if (contentDecoderMap != null) {
-                final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();
-                for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet())
{
-                    b2.register(entry.getKey(), entry.getValue());
-                }
-                b.add(new ResponseContentEncoding(b2.build()));
-            } else {
-                b.add(new ResponseContentEncoding());
-            }
-        }
         if (requestInterceptors != null) {
             for (final RequestInterceptorEntry entry: requestInterceptors) {
                 if (entry.postion == RequestInterceptorEntry.Postion.LAST) {
@@ -884,6 +863,24 @@ public class HttpClientBuilder {
                     ChainElements.REDIRECT.name());
         }
 
+        if (!contentCompressionDisabled) {
+            if (contentDecoderMap != null) {
+                final List<String> encodings = new ArrayList<>(contentDecoderMap.keySet());
+                final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();
+                for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet())
{
+                    b2.register(entry.getKey(), entry.getValue());
+                }
+                final Registry<InputStreamFactory> decoderRegistry = b2.build();
+                execChainDefinition.addFirst(
+                        new ContentCompressionExec(encodings, decoderRegistry, true),
+                        ChainElements.REDIRECT.name());
+            } else {
+                execChainDefinition.addFirst(
+                        new ContentCompressionExec(true),
+                        ChainElements.REDIRECT.name());
+            }
+        }
+
         // Optionally, add connection back-off executor
         if (this.backoffManager != null && this.connectionBackoffStrategy != null)
{
             execChainDefinition.addFirst(new BackoffStrategyExec(this.connectionBackoffStrategy,
this.backoffManager),

Copied: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
(from r1793320, httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseContentEncoding.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseContentEncoding.java&r1=1793320&r2=1793324&rev=1793324&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestResponseContentEncoding.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
Mon May  1 13:04:26 2017
@@ -24,46 +24,80 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.client5.http.protocol;
+package org.apache.hc.client5.http.impl.sync;
 
+import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.StandardMethods;
 import org.apache.hc.client5.http.config.RequestConfig;
 import org.apache.hc.client5.http.entity.DecompressingEntity;
 import org.apache.hc.client5.http.entity.GzipDecompressingEntity;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecRuntime;
+import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.HttpResponseInterceptor;
+import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
-import org.apache.hc.core5.http.protocol.BasicHttpContext;
-import org.apache.hc.core5.http.protocol.HttpContext;
 import org.junit.Assert;
-import org.junit.Ignore;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestContentCompressionExec {
+
+    @Mock
+    private ExecRuntime execRuntime;
+    @Mock
+    private ExecChain execChain;
+    @Mock
+    private ClassicHttpRequest originaRequest;
+
+    private HttpClientContext context;
+    private HttpHost host;
+    private ExecChain.Scope scope;
+    private ContentCompressionExec impl;
+
+    @Before
+    public void setup() {
+        host = new HttpHost("somehost", 80);
+        context = HttpClientContext.create();
+        scope = new ExecChain.Scope(new HttpRoute(host), originaRequest, execRuntime, context);
+        impl = new ContentCompressionExec();
+    }
 
-@Ignore
-public class TestResponseContentEncoding {
 
     @Test
     public void testContentEncodingNoEntity() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNull(entity);
     }
 
     @Test
     public void testNoContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("plain stuff");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof StringEntity);
@@ -71,14 +105,16 @@ public class TestResponseContentEncoding
 
     @Test
     public void testGzipContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("GZip");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof DecompressingEntity);
@@ -86,14 +122,16 @@ public class TestResponseContentEncoding
 
     @Test
     public void testGzipContentEncodingZeroLength() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("");
         original.setContentEncoding("GZip");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof StringEntity);
@@ -101,14 +139,16 @@ public class TestResponseContentEncoding
 
     @Test
     public void testXGzipContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("x-gzip");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof DecompressingEntity);
@@ -116,14 +156,16 @@ public class TestResponseContentEncoding
 
     @Test
     public void testDeflateContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("deFlaTe");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof DecompressingEntity);
@@ -131,14 +173,16 @@ public class TestResponseContentEncoding
 
     @Test
     public void testIdentityContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("identity");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertTrue(entity instanceof StringEntity);
@@ -146,18 +190,22 @@ public class TestResponseContentEncoding
 
     @Test(expected=HttpException.class)
     public void testUnknownContentEncoding() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("whatever");
         response.setEntity(original);
-        final HttpContext context = new BasicHttpContext();
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding(false);
-        interceptor.process(response, response.getEntity(), context);
+        impl = new ContentCompressionExec(false);
+
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
     }
 
     @Test
     public void testContentEncodingRequestParameter() throws Exception {
+        final ClassicHttpRequest request = new BasicClassicHttpRequest(StandardMethods.GET.name(),
host, "/");
         final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
         final StringEntity original = new StringEntity("encoded stuff");
         original.setContentEncoding("GZip");
@@ -167,11 +215,12 @@ public class TestResponseContentEncoding
                 .setContentCompressionEnabled(false)
                 .build();
 
-        final HttpContext context = new BasicHttpContext();
         context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
 
-        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
-        interceptor.process(response, response.getEntity(), context);
+        Mockito.when(execChain.proceed(request, scope)).thenReturn(response);
+
+        impl.execute(request, scope, execChain);
+
         final HttpEntity entity = response.getEntity();
         Assert.assertNotNull(entity);
         Assert.assertFalse(entity instanceof GzipDecompressingEntity);

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/impl/sync/TestContentCompressionExec.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message