private InputStream decompressBody ( ) { if ( ! decompress ) { return body ; } // if has no body, some server still set content-encoding header, // GZIPInputStream wrap empty input stream will cause exception. we should check this if ( method . equals ( Methods . HEAD ) || ( statusCode >= 100 && statusCode < 200 ) || statusCode == NOT_MODIFIED || statusCode == NO_CONTENT ) { return body ; } String contentEncoding = headers . getHeader ( NAME_CONTENT_ENCODING ) ; if ( contentEncoding == null ) { return body ; } //we should remove the content-encoding header here? switch ( contentEncoding ) { case "gzip" : try { return new GZIPInputStream ( body ) ; } catch ( IOException e ) { Closeables . closeQuietly ( body ) ; throw new RequestsException ( e ) ; } case "deflate" : // Note: deflate implements may or may not wrap in zlib due to rfc confusing. // here deal with deflate without zlib header return new InflaterInputStream ( body , new Inflater ( true ) ) ; case "identity" : case "compress" : //historic; deprecated in most applications and replaced by gzip or deflate default : return body ; } }
Wrap response input stream if it is compressed return input its self if not use compress