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 025e9b4
Show file tree
Hide file tree
Showing 3 changed files with 29 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.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

0 comments on commit 025e9b4

Please sign in to comment.