Decode Transfer-Encoding: gzip response bodies incrementally - #96
Open
oalders wants to merge 1 commit into
Open
Conversation
oalders
force-pushed
the
transfer-encoding
branch
from
August 14, 2026 00:59
f7868ac to
5d408b3
Compare
The gzip transfer-encoding handler buffered every de-chunked byte and gunzipped the whole body in one pass at end of stream, returning a scalar reference. This meant per-read returns were "" (surfaced as -1), so a caller's read cap was never consulted while the body streamed and the buffer grew without bound; the returned reference also made length() report the stringified ref rather than the payload. Decode incrementally with Compress::Raw::Zlib::Inflate (WANT_GZIP), mirroring the deflate branch. Each read now returns a plain string of just-decoded bytes, so length() is truthful, a caller's cap applies on every read, and peak memory tracks the read size rather than the response size. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #96 +/- ##
==========================================
+ Coverage 62.43% 68.09% +5.65%
==========================================
Files 4 4
Lines 402 398 -4
Branches 108 107 -1
==========================================
+ Hits 251 271 +20
+ Misses 104 80 -24
Partials 47 47 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
oalders
force-pushed
the
transfer-encoding
branch
from
August 14, 2026 01:01
5d408b3 to
3cd7927
Compare
robrwo
approved these changes
Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Net::HTTP::Methods::read_entity_bodyhandled aTransfer-Encoding: gzipresponse body by accumulating every de-chunked byte in a closure-local buffer
and gunzipping the whole thing in a single pass once the terminating
zero-length chunk arrived, then returning a scalar reference to the result.
That has two problems:
The read cap is never consulted while the body streams. Each read
returned
""(surfaced upstream as-1, "read again"), so the buffer grewwith no upper bound until the stream ended. A caller's read/size cap — e.g.
LWP::UserAgent'smax_size, enforced inLWP::Protocol::collect— onlysees the body after it has already been fully buffered and decompressed,
which defeats the point of the cap. Compression ratios stack on top of this.
Size accounting is wrong. Because the closure returned a reference,
length()measured the stringified reference (~19 bytes) rather than thedecoded payload.
Fix
Decode incrementally with
Compress::Raw::Zlib::Inflate->new(WindowBits => WANT_GZIP),mirroring the
deflatebranch immediately above it. Each read now returns aplain string of just-decoded bytes, so:
length()is truthful,Tests
t/te-gzip.tbuilds agzip, chunkedresponse split across many smallchunks and asserts correct decoding, truthful per-read lengths, and
incremental delivery. It fails against the previous code (returns a
SCALAR(0x…)) and passes with this change.t/http.tandt/socket-class.tcontinue to pass.🤖 Generated with Claude Code