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

List:       httpclient-users
Subject:    Re: HC 5 | Best recipe to handle Gzip content as response
From:       Bhuvan Gupta <bhuvangu () gmail ! com>
Date:       2020-09-02 20:26:43
Message-ID: CAF4ab9U9VH-BpPFpR6BW0N8-58_gsZTW19=5HhHC4cURNGfrnA () mail ! gmail ! com
[Download RAW message or body]


Thanks, will try it out . also added this mail link in SO

On Wed, Sep 2, 2020 at 11:29 PM Oleg Kalnichevski <olegk@apache.org> wrote:

> 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: 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