Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip Handling Error #31

Closed
jibasig opened this issue Aug 28, 2017 · 2 comments
Closed

gzip Handling Error #31

jibasig opened this issue Aug 28, 2017 · 2 comments

Comments

@jibasig
Copy link

jibasig commented Aug 28, 2017

I am using Retrofit 2.1.0 together with gson-Converter 2.1.0 and LoggingInterceptor 2.0.2.
If i call a service returning a response with "Content-Encoding: gzip" the following exception occurs.
java.io.IOException: ID1ID2: actual 0x00001fef != expected 0x00001f8b at okio.GzipSource.checkEqual(GzipSource.java:205) at okio.GzipSource.consumeHeader(GzipSource.java:120) at okio.GzipSource.read(GzipSource.java:73) at okio.RealBufferedSource.read(RealBufferedSource.java:45) at okio.ForwardingSource.read(ForwardingSource.java:35) at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:279) at okio.RealBufferedSource.request(RealBufferedSource.java:66) at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:387) at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:371) at okhttp3.internal.Util.bomAwareCharset(Util.java:412) at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:248) at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287) at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1325) at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:549) at com.google.gson.stream.JsonReader.peek(JsonReader.java:425) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:205) at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37) at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25) at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117) at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211) at retrofit2.OkHttpCall.execute(OkHttpCall.java:174) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:89)

First step could be just ignoring responses with content-Encoding=gzip and just returning the raw response from the interceptor. (this would disable logging for gzip responses). Another option could maybe be direct usage of GzipResource to decompress the response body. But I think, then you would have to remove the Content-Encoding:gzip header for further response handling by okHttp.

@jibasig
Copy link
Author

jibasig commented Aug 28, 2017

To see how the response is further handled, you can have a look at the okHttp BridgeInterceptor(line 100)
if (transparentGzip && "gzip".equalsIgnoreCase(networkResponse.header("Content-Encoding")) && HttpHeaders.hasBody(networkResponse)) { GzipSource responseBody = new GzipSource(networkResponse.body().source()); Headers strippedHeaders = networkResponse.headers().newBuilder() .removeAll("Content-Encoding") .removeAll("Content-Length") .build(); responseBuilder.headers(strippedHeaders); responseBuilder.body(new RealResponseBody(strippedHeaders, Okio.buffer(responseBody))); }
The LoggingInterceptor could handle gzip in a similar way.

jibasig added a commit to jibasig/LoggingInterceptor that referenced this issue Sep 6, 2017
@jibasig jibasig mentioned this issue Sep 6, 2017
jibasig added a commit to jibasig/LoggingInterceptor that referenced this issue Sep 6, 2017
@chihung93
Copy link

chihung93 commented Jul 12, 2018

Version 2.0.6
I have the same issue:

W/System.err: java.io.IOException: ID1ID2: actual 0x00001fef != expected 0x00001f8b
        at okio.GzipSource.checkEqual(GzipSource.java:205)
        at okio.GzipSource.consumeHeader(GzipSource.java:120)
        at okio.GzipSource.read(GzipSource.java:73)
        at okio.RealBufferedSource.read(RealBufferedSource.java:47)
        at okio.ForwardingSource.read(ForwardingSource.java:35)
        at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:290)
        at okio.RealBufferedSource.request(RealBufferedSource.java:68)
        at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:418)
        at okio.RealBufferedSource.rangeEquals(RealBufferedSource.java:402)
        at okhttp3.internal.Util.bomAwareCharset(Util.java:432)
        at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:249)
        at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
        at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1325)
        at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:549)
        at com.google.gson.stream.JsonReader.peek(JsonReader.java:425)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:205)
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
        at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:122)
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:217)
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
        at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:11194)
        at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
        at io.reactivex.Observable.subscribe(Observable.java:11194)
        at io.reactivex.internal.operators.flowable.FlowableFromObservable.subscribeActual(FlowableFromObservable.java:29)
        at io.reactivex.Flowable.subscribe(Flowable.java:13234)
        at io.reactivex.internal.operators.flowable.FlowableOnBackpressureLatest.subscribeActual(FlowableOnBackpressureLatest.java:32)
        at io.reactivex.Flowable.subscribe(Flowable.java:13234)
        at io.reactivex.Flowable.subscribe(Flowable.java:13180)
        at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)

@ihsanbal ihsanbal closed this as completed Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants