Closed Etery13 closed 7 years ago
This isn't a reproducible bug or something that looks like it requires a fix in OkHttp (yet). Can you please post on stackoverflow with a reproducible test case, or at least your client code.
Please include in your stackoverflow post whether it fails the same way, with or without HttpLoggingInterceptor.
我也老是出现这个异常 急求解决
Google Translate: "I also always appear this exception urgently needed to solve"
@shuaimango can you link to your post on stackoverflow?
Hi, This is a bug quite hard to reproduce. It happens when an empty Gzip stream is returned from the server side as response body and HTTPLoggingInterceptor is set to BODY level. It tries to log the body but the okio.GzipSource.consumeHeader requires a 10 bytes Gzip header. The check at okio.RealBufferedSource.require throws an EOFException.
The responseBody.contentLength is -1 in this case. Anyhow a -1 contentLength should not be logged, so I suggest to insert another check at HTTPLoggingInterceptor line 238
else if (responseBody.contentLength() <= 0) { logger.log("<-- END HTTP (content length <= 0)"); }
Workaround is not to log the Response BODY. (Real life example: Microsoft PowerBI API returnes a 200 OK response with a 0 byte gzip body rather than an empty json.)
Can you report the bug to the maintainers of the Microsoft PowerBI API? Their API is wrong.
@swankjesse I'm not sure about it. It's a response to a POST request.
The method hasBody(Response response) in okhttp3.internal.http.HttpHeaders returns true if the response code is 200. In case of a 200 response with empty body (Content-Length: 0) shouldn't it return false?
Full header: access-control-allow-credentials →true access-control-allow-origin →chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop cache-control →no-store, must-revalidate, no-cache content-encoding →gzip content-length →0 content-type →application/octet-stream date →Sun, 25 Nov 2018 13:40:47 GMT requestid →709adf93-2f60-4a7e-9fdb-dfbdc5457195 server →Microsoft-HTTPAPI/2.0,Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0 status →200 strict-transport-security →max-age=31536000; includeSubDomains x-content-type-options →nosniff x-frame-options →deny
The content-encoding is not Gzip because it doesn’t have the required 10-byte Gzip header.
Getting the same issue on a 202 No Content with a zero length response body
@kngmat004 you should report the problem to whoever hosts the server. If it's the same as above it's a bug.
If you really need to handle it in the client, because the server can't be fixed, consider using a network interceptor to change headers to work around it.
If you think it's a bug in OkHttp please provide a reproducible example.
Dear community! Could you please help me with my bug? There is response, request and an exception in logs below. I expect 404 code response but my tests failed because of weird exception. I replaced url and token in logs with dummy values. logs: