On Mon, 2018-05-07 at 09:24 -0600, Gary Gregory wrote:
> What could be more useful is a more general solution in a new module
> based
> on Apache Commons Compress that calls
> org.apache.commons.compress.compressors.CompressorStreamFactory.creat
> eCompressorOutputStream(String,
> OutputStream).
> 
> That would give you support for:
> 
> GZIP
> BZIP2
> XZ
> PACK200
> LZMA
> DEFLATE
> SNAPPY_FRAMED
> LZ4_BLOCK
> LZ4_FRAMED
> ZSTANDARD
> 
> Gary
> 

Hi Philippe

Yes, this sounds like a useful feature. It would likely be too big for
4.5.x but could go into 4.6.x or 5.x.

It would also be super if you could look into other compression feature
requests at the same time.

Cheers

Oleg


> On Mon, May 7, 2018 at 9:15 AM, Philippe Mouawad <
> [email protected]> wrote:
> 
> > Hello,
> > There are sometimes a requirement to automatically gzip the request
> > body
> > whenever Content-Encoding is set to gzip.
> > 
> > Would you find it interesting to add this feature to HttpClient ?
> > 
> > The implementation would look like:
> > 
> >     private static final class GzipHttpRequestInterceptor
> > implements
> > HttpRequestInterceptor {
> >         @Override
> >         public void process(HttpRequest request, HttpContext
> > context)
> > throws HttpException, IOException {
> >             if(request instanceof HttpEntityEnclosingRequest) {
> >                 Header header = request.getFirstHeader("
> > Content-Encoding");
> >                 if(header != null &&
> > "gzip".equals(header.getValue())) {
> >                     HttpEntityEnclosingRequest enclosingRequest =
> > (HttpEntityEnclosingRequest) request;
> >                     HttpEntity entity =
> > enclosingRequest.getEntity();
> >                     ByteArrayOutputStream out = new
> > ByteArrayOutputStream();
> >                     try (GZIPOutputStream gzipOS = new
> > GZIPOutputStream(out)) {
> >                         entity.writeTo(gzipOS);
> >                     }
> >                     enclosingRequest.setEntity(new
> > ByteArrayEntity(out.toByteArray()));
> >                 }
> >             }
> >         }
> >     }
> > 
> > 
> > Use could add it to processing like this:
> > 
> >    - builder.addInterceptorFirst(new GzipHttpRequestInterceptor()
> > );
> > 
> > Or it could be enabled by default.
> > 
> > 
> > Questions:
> > 
> >    - Would you accept it as a PR ?
> >    - Do you see immediate improvements in the provided code ?
> > 
> > Thanks
> > --
> > Regards
> > Philippe Mouawad.
> > Ubik-Ingénierie
> > 

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

Reply via email to