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

Handling of empty responses when dealing with GZip #2177

Closed
czardoz opened this issue Apr 16, 2016 · 5 comments
Closed

Handling of empty responses when dealing with GZip #2177

czardoz opened this issue Apr 16, 2016 · 5 comments

Comments

@czardoz
Copy link
Contributor

czardoz commented Apr 16, 2016

This is a continuation of the discussion in #2176

Basically, what should request do when a server returns an empty response with the Content-Encoding header set to gzip?

@simov
Copy link
Member

simov commented Apr 16, 2016

Basically zlib throws on stream write/end in cases when the compressed data is corrupted. It turns out that similar error is thrown on empty response body as well.

I'm not able to find a way to determine if the incoming response stream contains any data prior piping it to zlib. So the underlying zlib module throws and the error is being forwarded to the end user. Unfortunately at this point your only option would be to swallow the error.

@czardoz
Copy link
Contributor Author

czardoz commented Apr 16, 2016

As mentioned in RFC 7230, it seems that there are well defined conditions under which a response may have no body.

All 1xx (Informational), 204 (No Content), and 304 (Not Modified)
   responses do not include a message body.  All other responses do
   include a message body, although the body might be of zero length.

and

Responses to the HEAD request method (Section 4.3.2
   of [RFC7231]) never include a message body [snip]

In these scenarios at least, can we ensure that request does not throw an error, and returns the response body as an empty string?

For example, having a 204 response to a GET is a perfectly valid scenario, and not an error. We should not forward an error to the user in this case, I think.

@simov
Copy link
Member

simov commented Apr 16, 2016

All 1xx (Informational), 204 (No Content), and 304 (Not Modified)

That sounds reasonable, though as you are aware handling those status codes does not guarantee no errors.

Errors should be forwarded always, that's the point, the status code check should be placed before piping to zlib (we are on the same page).

@czardoz
Copy link
Contributor Author

czardoz commented Apr 16, 2016

Yep, I agree with you.. request shouldn't accidentally catch legitimate errors.

@simov
Copy link
Member

simov commented Apr 17, 2016

Implemented in #2176

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

2 participants