60
60
import cz .msebera .android .httpclient .client .RedirectHandler ;
61
61
import cz .msebera .android .httpclient .client .methods .HttpEntityEnclosingRequestBase ;
62
62
import cz .msebera .android .httpclient .client .methods .HttpHead ;
63
+ import cz .msebera .android .httpclient .client .methods .HttpPatch ;
63
64
import cz .msebera .android .httpclient .client .methods .HttpPost ;
64
65
import cz .msebera .android .httpclient .client .methods .HttpPut ;
65
66
import cz .msebera .android .httpclient .client .methods .HttpUriRequest ;
@@ -371,10 +372,18 @@ public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inpu
371
372
return false ;
372
373
373
374
byte [] signature = new byte [2 ];
374
- int readStatus = inputStream .read (signature );
375
- inputStream .unread (signature );
375
+ int count = 0 ;
376
+ try {
377
+ while (count < 2 ) {
378
+ int readCount = inputStream .read (signature , count , 2 - count );
379
+ if (readCount < 0 ) return false ;
380
+ count = count + readCount ;
381
+ }
382
+ } finally {
383
+ inputStream .unread (signature , 0 , count );
384
+ }
376
385
int streamHeader = ((int ) signature [0 ] & 0xff ) | ((signature [1 ] << 8 ) & 0xff00 );
377
- return readStatus == 2 && GZIPInputStream .GZIP_MAGIC == streamHeader ;
386
+ return GZIPInputStream .GZIP_MAGIC == streamHeader ;
378
387
}
379
388
380
389
/**
@@ -1595,6 +1604,7 @@ private static class InflatingEntity extends HttpEntityWrapper {
1595
1604
InputStream wrappedStream ;
1596
1605
PushbackInputStream pushbackStream ;
1597
1606
GZIPInputStream gzippedStream ;
1607
+
1598
1608
public InflatingEntity (HttpEntity wrapped ) {
1599
1609
super (wrapped );
1600
1610
}
@@ -1603,8 +1613,7 @@ public InflatingEntity(HttpEntity wrapped) {
1603
1613
public InputStream getContent () throws IOException {
1604
1614
wrappedStream = wrappedEntity .getContent ();
1605
1615
pushbackStream = new PushbackInputStream (wrappedStream , 2 );
1606
- Header enc = wrappedEntity .getContentEncoding ();
1607
- if ((enc != null && "gzip" .equalsIgnoreCase (enc .getValue ())) || isInputStreamGZIPCompressed (pushbackStream )) {
1616
+ if (isInputStreamGZIPCompressed (pushbackStream )) {
1608
1617
gzippedStream = new GZIPInputStream (pushbackStream );
1609
1618
return gzippedStream ;
1610
1619
} else {
0 commit comments