Skip to content

Commit 4bffe5f

Browse files
committed
Using upstream implementation of HttpPatch method, Fixed GZIP stream decoding/detection, Closing android-async-http#932
1 parent a5399d8 commit 4bffe5f

File tree

2 files changed

+14
-64
lines changed

2 files changed

+14
-64
lines changed

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import cz.msebera.android.httpclient.client.RedirectHandler;
6161
import cz.msebera.android.httpclient.client.methods.HttpEntityEnclosingRequestBase;
6262
import cz.msebera.android.httpclient.client.methods.HttpHead;
63+
import cz.msebera.android.httpclient.client.methods.HttpPatch;
6364
import cz.msebera.android.httpclient.client.methods.HttpPost;
6465
import cz.msebera.android.httpclient.client.methods.HttpPut;
6566
import cz.msebera.android.httpclient.client.methods.HttpUriRequest;
@@ -371,10 +372,18 @@ public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inpu
371372
return false;
372373

373374
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+
}
376385
int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00);
377-
return readStatus == 2 && GZIPInputStream.GZIP_MAGIC == streamHeader;
386+
return GZIPInputStream.GZIP_MAGIC == streamHeader;
378387
}
379388

380389
/**
@@ -1595,6 +1604,7 @@ private static class InflatingEntity extends HttpEntityWrapper {
15951604
InputStream wrappedStream;
15961605
PushbackInputStream pushbackStream;
15971606
GZIPInputStream gzippedStream;
1607+
15981608
public InflatingEntity(HttpEntity wrapped) {
15991609
super(wrapped);
16001610
}
@@ -1603,8 +1613,7 @@ public InflatingEntity(HttpEntity wrapped) {
16031613
public InputStream getContent() throws IOException {
16041614
wrappedStream = wrappedEntity.getContent();
16051615
pushbackStream = new PushbackInputStream(wrappedStream, 2);
1606-
Header enc = wrappedEntity.getContentEncoding();
1607-
if ((enc != null && "gzip".equalsIgnoreCase(enc.getValue())) || isInputStreamGZIPCompressed(pushbackStream)) {
1616+
if (isInputStreamGZIPCompressed(pushbackStream)) {
16081617
gzippedStream = new GZIPInputStream(pushbackStream);
16091618
return gzippedStream;
16101619
} else {

library/src/main/java/com/loopj/android/http/HttpPatch.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)