You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Bhuvan Gupta <bh...@gmail.com> on 2020/09/02 07:26:27 UTC
HC 5 | Best recipe to handle Gzip content as response
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
> 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.
Re: HC 5 | Best recipe to handle Gzip content as response
Posted by Bhuvan Gupta <bh...@gmail.com>.
Thanks, will try it out . also added this mail link in SO
On Wed, Sep 2, 2020 at 11:29 PM Oleg Kalnichevski <ol...@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
>
>
Re: HC 5 | Best recipe to handle Gzip content as response
Posted by Oleg Kalnichevski <ol...@apache.org>.
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