Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D284D10E0D for ; Thu, 20 Feb 2014 10:54:17 +0000 (UTC) Received: (qmail 21609 invoked by uid 500); 20 Feb 2014 10:54:17 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 21460 invoked by uid 500); 20 Feb 2014 10:54:14 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 21452 invoked by uid 99); 20 Feb 2014 10:54:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 10:54:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FRT_STOCK2 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 10:54:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8092423889BF for ; Thu, 20 Feb 2014 10:53:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1570142 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/config/ main/java/org/apache/http/client/protocol/ test/java/org/apache/http/client/protocol/ Date: Thu, 20 Feb 2014 10:53:52 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140220105352.8092423889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Thu Feb 20 10:53:52 2014 New Revision: 1570142 URL: http://svn.apache.org/r1570142 Log: HTTPCLIENT-1464: ability to enable / disable content decompression at request level Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java?rev=1570142&r1=1570141&r2=1570142&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java Thu Feb 20 10:53:52 2014 @@ -51,6 +51,7 @@ public class RequestConfig implements Cl private final int connectionRequestTimeout; private final int connectTimeout; private final int socketTimeout; + private final boolean decompressionEnabled; RequestConfig( final boolean expectContinueEnabled, @@ -67,7 +68,8 @@ public class RequestConfig implements Cl final Collection proxyPreferredAuthSchemes, final int connectionRequestTimeout, final int connectTimeout, - final int socketTimeout) { + final int socketTimeout, + final boolean decompressionEnabled) { super(); this.expectContinueEnabled = expectContinueEnabled; this.proxy = proxy; @@ -84,6 +86,7 @@ public class RequestConfig implements Cl this.connectionRequestTimeout = connectionRequestTimeout; this.connectTimeout = connectTimeout; this.socketTimeout = socketTimeout; + this.decompressionEnabled = decompressionEnabled; } /** @@ -263,6 +266,17 @@ public class RequestConfig implements Cl return socketTimeout; } + /** + * Determines whether compressed entities should be decompressed automatically. + *

+ * Default: true + * + * @since 4.4 + */ + public boolean isDecompressionEnabled() { + return decompressionEnabled; + } + @Override protected RequestConfig clone() throws CloneNotSupportedException { return (RequestConfig) super.clone(); @@ -286,6 +300,7 @@ public class RequestConfig implements Cl builder.append(", connectionRequestTimeout=").append(connectionRequestTimeout); builder.append(", connectTimeout=").append(connectTimeout); builder.append(", socketTimeout=").append(socketTimeout); + builder.append(", decompressionEnabled=").append(decompressionEnabled); builder.append("]"); return builder.toString(); } @@ -310,7 +325,8 @@ public class RequestConfig implements Cl .setProxyPreferredAuthSchemes(config.getProxyPreferredAuthSchemes()) .setConnectionRequestTimeout(config.getConnectionRequestTimeout()) .setConnectTimeout(config.getConnectTimeout()) - .setSocketTimeout(config.getSocketTimeout()); + .setSocketTimeout(config.getSocketTimeout()) + .setDecompressionEnabled(config.isDecompressionEnabled()); } public static class Builder { @@ -330,6 +346,7 @@ public class RequestConfig implements Cl private int connectionRequestTimeout; private int connectTimeout; private int socketTimeout; + private boolean decompressionEnabled; Builder() { super(); @@ -341,6 +358,7 @@ public class RequestConfig implements Cl this.connectionRequestTimeout = -1; this.connectTimeout = -1; this.socketTimeout = -1; + this.decompressionEnabled = true; } public Builder setExpectContinueEnabled(final boolean expectContinueEnabled) { @@ -418,6 +436,11 @@ public class RequestConfig implements Cl return this; } + public Builder setDecompressionEnabled(final boolean decompressionEnabled) { + this.decompressionEnabled = decompressionEnabled; + return this; + } + public RequestConfig build() { return new RequestConfig( expectContinueEnabled, @@ -434,7 +457,8 @@ public class RequestConfig implements Cl proxyPreferredAuthSchemes, connectionRequestTimeout, connectTimeout, - socketTimeout); + socketTimeout, + decompressionEnabled); } } Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java?rev=1570142&r1=1570141&r2=1570142&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java Thu Feb 20 10:53:52 2014 @@ -36,6 +36,7 @@ import org.apache.http.HttpException; import org.apache.http.HttpResponse; import org.apache.http.HttpResponseInterceptor; import org.apache.http.annotation.Immutable; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.DeflateDecompressingEntity; import org.apache.http.client.entity.GzipDecompressingEntity; import org.apache.http.protocol.HttpContext; @@ -74,9 +75,11 @@ public class ResponseContentEncoding imp final HttpContext context) throws HttpException, IOException { final HttpEntity entity = response.getEntity(); + final HttpClientContext clientContext = HttpClientContext.adapt(context); + final RequestConfig requestConfig = clientContext.getRequestConfig(); // entity can be null in case of 304 Not Modified, 204 No Content or similar // check for zero length entity. - if (entity != null && entity.getContentLength() != 0) { + if (requestConfig.isDecompressionEnabled() && entity != null && entity.getContentLength() != 0) { final Header ceheader = entity.getContentEncoding(); if (ceheader != null) { final HeaderElement[] codecs = ceheader.getElements(); Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java?rev=1570142&r1=1570141&r2=1570142&view=diff ============================================================================== --- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java (original) +++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java Thu Feb 20 10:53:52 2014 @@ -31,6 +31,7 @@ import org.apache.http.HttpException; import org.apache.http.HttpResponse; import org.apache.http.HttpResponseInterceptor; import org.apache.http.HttpVersion; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.DeflateDecompressingEntity; import org.apache.http.client.entity.GzipDecompressingEntity; import org.apache.http.entity.StringEntity; @@ -154,4 +155,25 @@ public class TestResponseContentEncoding interceptor.process(response, context); } + @Test + public void testContentEncodingRequestParameter() throws Exception { + final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); + final StringEntity original = new StringEntity("encoded stuff"); + original.setContentEncoding("GZip"); + response.setEntity(original); + + final RequestConfig config = RequestConfig.custom() + .setDecompressionEnabled(false) + .build(); + + final HttpContext context = new BasicHttpContext(); + context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); + + final HttpResponseInterceptor interceptor = new ResponseContentEncoding(); + interceptor.process(response, context); + final HttpEntity entity = response.getEntity(); + Assert.assertNotNull(entity); + Assert.assertFalse(entity instanceof GzipDecompressingEntity); + } + }