Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/protocol/http/body/deflate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ def read
return if @stream.finished?

# The stream might have been closed while waiting for the chunk to come in.
if chunk = super
@input_length += chunk.bytesize

chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)

@output_length += chunk.bytesize

return chunk
elsif !@stream.closed?
while chunk = super
unless chunk.empty?
@input_length += chunk.bytesize

chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)

@output_length += chunk.bytesize

return chunk
end
end

if !@stream.closed?
chunk = @stream.finish

@output_length += chunk.bytesize
Expand Down
1 change: 1 addition & 0 deletions releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
- Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.

## v0.58.1

Expand Down
9 changes: 9 additions & 0 deletions test/protocol/http/body/deflate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@
)
end
end

with "empty chunks" do
let(:body) {Protocol::HTTP::Body::Buffered.new(["", "bar", ""])}

it "can read empty chunks" do
expect(decompressed_body.read).to be == "bar"
expect(decompressed_body.read).to be == nil
end
end
end
Loading