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

Inflater handle empty streams #625

Merged
merged 1 commit into from Nov 9, 2020

Conversation

LukaszMaslej
Copy link

Hello,
This prevents the issue of Zlib::BufError errors raised when reading
by Inflater empty streams (should fix #624).

Thanks!

@tarcieri
Copy link
Member

tarcieri commented Nov 9, 2020

@LukaszMaslej seems like a reasonable enough workaround, although there are some RuboCop failures

@@ -16,7 +16,7 @@ def readpartial(*args)
if chunk
chunk = zstream.inflate(chunk)
elsif !zstream.closed?
zstream.finish
zstream.finish if zstream.total_in > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuboCop suggests the following here:

Suggested change
zstream.finish if zstream.total_in > 0
zstream.finish if zstream.total_in.positive?

Comment on lines 179 to 188
res.body = case req["Accept-Encoding"]
when "gzip" then
res["Content-Encoding"] = "gzip"
""
when "deflate" then
res["Content-Encoding"] = "deflate"
""
else
""
end
Copy link
Member

@tarcieri tarcieri Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuboCop suggests moving the "" out of the conditional since it's the same for all branches

Suggested change
res.body = case req["Accept-Encoding"]
when "gzip" then
res["Content-Encoding"] = "gzip"
""
when "deflate" then
res["Content-Encoding"] = "deflate"
""
else
""
end
res.body = ""
case req["Accept-Encoding"]
when "gzip" then
res["Content-Encoding"] = "gzip"
when "deflate" then
res["Content-Encoding"] = "deflate"
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarcieri fair suggestions, fixed.

@tarcieri
Copy link
Member

tarcieri commented Nov 9, 2020

The test failures appear to be unrelated. Thanks for the fix!

@tarcieri tarcieri merged commit 6f5ea22 into httprb:master Nov 9, 2020
@tarcieri tarcieri mentioned this pull request May 13, 2021
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

Successfully merging this pull request may close these issues.

Zlib::BufError in case of empty body response with Content-Encoding and auto_inflate use
2 participants