On Wed, 2020-09-02 at 12:56 +0530, Bhuvan Gupta wrote:
> Community,
> from link
> <
> https://stackoverflow.com/questions/63462901/httpclient5-0-how-to-use-gzip-in-asynchronous-mode
> >
> we
> understand that automatic content decompression is not supported.
> So is the below recipe a good way to handle the gzip content ?
> I search
> 

It is good enough for small payloads. For large payloads one should
build a custom AsyncEntityConsumer and decompress incoming content
without buffering it in memory.

Oleg


> > httpclient.execute(this.post, new
> > FutureCallback<SimpleHttpResponse>() {
> >                 @Override
> >                 public void completed(SimpleHttpResponse response)
> > {
> >                         String resXML = null;
> > 
> >                         Header contentEncoding =
> > response.getHeader("Content-Encoding");
> > 
> >                         if(contentEncoding != null
> >                               &&
> > "gzip".equalsIgnoreCase(contentEncoding.getValue())){
> > 
> >                             HttpEntity entity = new
> > GzipDecompressingEntity(new
> > ByteArrayEntity(response.getBodyBytes(),
> > ContentType.APPLICATION_XML));
> >                             resXML = EntityUtils.toString(entity,
> > "UTF-8");
> > 
> >                         }else{
> >                             resXML = response.getBodyText();
> >                         }
> > 
> >                 }
> > 
> > Also asked on SO, i will sync recommendations there also.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to