You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2019/02/12 09:46:00 UTC
[jira] [Resolved] (HTTPASYNC-148) ResponseContentEncoding not
working with HttpAsyncClient
[ https://issues.apache.org/jira/browse/HTTPASYNC-148?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPASYNC-148.
-----------------------------------------
Resolution: Invalid
One cannot mix inherently blocking {{InputStream}} / {{OutputStream}} based content processors and non-blocking protocol handlers. It just does not work like that.
Oleg
> ResponseContentEncoding not working with HttpAsyncClient
> --------------------------------------------------------
>
> Key: HTTPASYNC-148
> URL: https://issues.apache.org/jira/browse/HTTPASYNC-148
> Project: HttpComponents HttpAsyncClient
> Issue Type: Bug
> Affects Versions: 4.1.4
> Environment: Windows 10, Oracle JDK 1.8.0_161
> Reporter: Siqi Li
> Priority: Major
>
> Here's my code snippet:
> {code:java}
> import java.io.ByteArrayInputStream;
> import java.util.zip.GZIPInputStream;
> import org.apache.commons.io.IOUtils;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.client.protocol.RequestAcceptEncoding;
> import org.apache.http.client.protocol.ResponseContentEncoding;
> import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
> import org.apache.http.impl.nio.client.HttpAsyncClients;
> import org.apache.http.util.EntityUtils;
> public class Issue20190211 {
> public static void main(String[] args) throws Exception {
> try (CloseableHttpAsyncClient client = HttpAsyncClients.custom()
> .addInterceptorFirst(new RequestAcceptEncoding())
> .addInterceptorFirst(new ResponseContentEncoding())
> .build()) {
> client.start();
> final HttpResponse response = client.execute(
> new HttpGet("http://example.com"), null).get();
> final byte[] respBytes = EntityUtils.toByteArray(response.getEntity());
> System.out.println(new String(respBytes, "UTF-8")); // Prints gibberish
> final String decompressed = IOUtils.toString(
> new GZIPInputStream(new ByteArrayInputStream(respBytes)), "UTF-8");
> System.out.println(decompressed); // This gives me the correct result
> }
> }
> }
> {code}
> What this looks like to me is that the HttpRequestInterceptor is working, since the server is responding with gzipped content, but the HttpResponseInterceptor is not, since I still have to manually decompress the content.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org