[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-users
Subject:    Re: Accept-Encoding:gzip
From:       Bindul Bhowmik <bindulbhowmik () gmail ! com>
Date:       2017-05-25 22:09:12
Message-ID: CA+G35O2-ZuBXUhj0DjxkKF34_pdvtaUydVC5n5_rH+vKwZ2ObQ () mail ! gmail ! com
[Download RAW message or body]

On Thu, May 25, 2017 at 11:13 AM, Shaun Elliott <javamonkey79@gmail.com> wrote:
> The following code works in v4.2.x
> 
> public class RestClientTest {
> private static final Executor EXECUTOR = Executor.newInstance();
> 
> public static void main(String[] args) throws IOException {
> Request request =
> Request.Get("http://www.google.com/").addHeader("Accept-Encoding",
> "gzip");
> Response response = request.execute();//        Response
> response = EXECUTOR.execute(request);
> Header[] headers = response.returnResponse().getAllHeaders();
> for (Header header : headers) {
> System.out.println(header);
> }
> }
> }
> 
> 
> Returned in response headers:
> 
> Content-Encoding: gzip
> 
> 
> But, if I update my version, to 4.3.x+ it no longer works. It appears based
> on this comment:
> 
> https://issues.apache.org/jira/browse/HTTPCLIENT-816?focusedCommentId=13998604&page= \
> com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13998604 
> That gzip encoding was only available in 4.2.x. Is this the case, or is
> there another explanation? Can we get gzip encoding in versions later than
> 4.2.x?

Shaun,

You can achieve that by using the RequestAcceptEncoding request
interceptor, and the ResponseContentEncoding response interceptor. To
use interceptors, see the tutorial section 1.4 [1]. Note that the
ResponseContentEncoding provides 'transparent' content decompression,
and after the content is decompressed you will not see the
Content-Encoding header even though the entity may be compressed on
the wire.

If you are using HttpClients or HttpClientBuilder, the two
interceptors should automatically be added for you, unless you
explicitly call disableContentCompression or add custom compression
handling using setContentDecoderRegistry [2] method.

- Bindul

[1] http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#protocol_interceptors
 [2] http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/HttpClientBuilder.html#setContentDecoderRegistry(java.util.Map)


> 
> Thanks,
> Shaun Elliott

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic