-
Notifications
You must be signed in to change notification settings - Fork 466
chunked encoding + GZIP prevents keep-alive #367
Copy link
Copy link
Labels
🚨This issue needs some love.This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Metadata
Metadata
Assignees
Labels
🚨This issue needs some love.This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
GZIPInputStream.read()starts returning -1 once it finishes reading the gzip trailer. Depending on the underlyingInputStream, this may occur before it has finished consuming the underlyingInputStream.In particular, if the underlying
InputStreamis aChunkedInputStream, theChunkedInputStreamnever reads the final chunk header (which indicates a chunk of length 0).When
ChunkedInputStream.close()is called, it is in a non-STATE_DONE state, and does not callHttpClient.finished(), which is required for theHttpClientobject to get into the keep alive cache.One possible fix is here:
https://github.com/google/google-http-java-client/blob/acdaeacc3c43402d795266d2ebcb584abe918961/google-http-client/src/main/java/com/google/api/client/http/HttpResponse.java#L363
Rather than returning a
GZIPInputStream, return a proxy input stream that retains references to both the gzip stream and the underlying stream. The proxy'sclose()method first consumes the underlying stream by callingread()and then callsclose()on the gzip stream.