-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
0-byte gzip response causes java.io.EOFException #1550
Comments
As a workaround, with HttpURLConnection at least, you can set Accept-Encoding: gzip yourself, and then you'd need to deal with wrapping the InputStream in a GZIPInputStream yourself. Not so sure about retrofit / other APIs. I'd say this is a problem with the OneDrive server. Isn't a minimum gzip encoded content those 10 bytes? Anything smaller is actually not gzip encoded? |
@nfuller, Not sure about the minimum gzip encoded content length. If it's indeed 10 bytes - will file an issue against OneDrive API. Workaround is pretty simple: supply |
@igokoro I'm only going by what I've seen in the past, but it seems to be backed up by http://en.wikipedia.org/wiki/Gzip#File_format Yes: identity encoding would work, but I assumed you would want compression. I was thinking about what OkHttp could or should do here. If dealing with gzip, when content-length == 0, it could pretend that was valid? If content length was > 0 but < 10 it would be sure that was invalid but would it be ok to swallow that? 10 bytes is the minimum, but it doesn't mean those 10 are valid. None of these seem to be things that OkHttp could concern itself with. okio, on the other hand, could maybe be more informative when the gzip data is invalid. Until now I hadn't noticed that okio had it's own gzip implementation. This isn't a criticism of okio: For example, Android's GZIPIntputStream isn't any more friendly: if < 10 header bytes are present you'll just see an EOFException without explanation, which is just the same as okio. |
Yeah, this is a bug in your server and they should fix it. Work around by explicitly requesting identity encoding. |
@nfuller, @swankjesse got your point. Let's see what OneDrive backend developers will respond. |
I have the same problem with another server. According to HTTP/1.1 Gzip Coding, the content is compressed with
As far as I understand this, it means that gzipped content consists of a series of chunks (members), which have a 10 octet long header. So, it seems to be possible that there are zero members, in which case the content has zero octets. Even if a series would really mean a series with at least one member, I guess it would increase compatibility to allow zero-length gzip responses and do no harm. What do you think? Are you sure that there must be at least one member (i.e. at least 10 octets), and if yes, wouldn't it be robust implementation to accept responses with zero members and treat them as what they are, namely empty responses? |
The
|
This was also the first thing I have tried :) Although, I wouldn't say that this is normative, especially as RFC 1952 just talks about a series and there are implementations (for instance, above-mentioned servers, or this one) which interpret the standard so that zero chunks are possible. Following the robustness principle (be compatible in what you receive and strict in what you send), I suggest that 0-byte or multi-chunk gzip responses should be accepted. Am I right that I guess okio would be a better place to talk about that? |
Let's discuss here: |
I'm using Retrofit (1.9.0) with OhHttp/okio (2.3.0/1.3.0) to implement communication with OneDrive REST API. While almost everything works amazingly well, there is a problem with
java.io.EOFException
on action.copy.OneDrive server returns
Under the hood OkHttp includes
Accept-Encoding: gzip
into request headers, so server legitimately returns a 0-byte gzip-like response.One the response side,
com.squareup.okhttp.internal.http.HttpEngine
unzips response intoGzipSource
in methodunzip(Response)
. The problem is thatGzipSource
tries to consume 10-byte gzip header from 0-length stream, so thejava.io.EOFException
is thrown because of seemingly missing 10 bytes.My guess is that the problem is in the
HttpEngine.unzip(Response)
method: it checks if response is actually compressed and if the response body is not null. But it fails to check content length to know if there is something is the stream.The problem is even worse because the original
Content-Length
andContent-Encoding
headers are stripped off and on the client side there is no way to know if it's safe read from the response stream.Here is the original stack trace from my application:
The text was updated successfully, but these errors were encountered: