Skip to content

Commit

Permalink
Inflater handle empty streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Maslej authored and Lukasz Maslej committed Nov 9, 2020
1 parent a0f540f commit 7484c86
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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 > 0
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-Encode 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-Encode 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
15 changes: 15 additions & 0 deletions spec/support/dummy_server/servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,20 @@ 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"
""
else
""
end
end
end
end

0 comments on commit 7484c86

Please sign in to comment.