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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/http/response/inflater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def readpartial(*args)
if chunk
chunk = zstream.inflate(chunk)
elsif !zstream.closed?
zstream.finish
zstream.finish if zstream.total_in.positive?
zstream.close
end
chunk
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,22 @@ def setsockopt(*args)

expect(response.to_s).to eq("#{body}-deflated")
end

it "returns empty body for no content response where Content-Encoding is gzip" do
client = HTTP.use(:auto_inflate).headers("Accept-Encoding" => "gzip")
body = "Hello!"
response = client.post("#{dummy.endpoint}/no-content-204", :body => body)

expect(response.to_s).to eq("")
end

it "returns empty body for no content response where Content-Encoding is deflate" do
client = HTTP.use(:auto_inflate).headers("Accept-Encoding" => "deflate")
body = "Hello!"
response = client.post("#{dummy.endpoint}/no-content-204", :body => body)

expect(response.to_s).to eq("")
end
end

context "with :normalize_uri" do
Expand Down
12 changes: 12 additions & 0 deletions spec/support/dummy_server/servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,17 @@ def do_#{method.upcase}(req, res)
"#{req.body}-raw"
end
end

post "/no-content-204" do |req, res|
res.status = 204
res.body = ""

case req["Accept-Encoding"]
when "gzip" then
res["Content-Encoding"] = "gzip"
when "deflate" then
res["Content-Encoding"] = "deflate"
end
end
end
end