fix: decode Transfer-Encoding: chunked request bodies - #50
Open
maddie wants to merge 1 commit into
Open
Conversation
The Chunked body branch read the raw stream in fixed 1024-byte blocks and never decoded it. With a finite payload the client keeps the connection open (keep-alive, no half-close), the final block never fills, and the server blocks forever instead of answering — hanging any chunked uploader after its first payload (librespeed#49, root cause of librespeed/speedtest-cli#122). Parse the chunked framing per RFC 9112 §7.1: chunk-size line (extensions ignored), chunk data, trailing CRLF, then the 0-size last chunk and the trailer section. Verified with curl -H 'Transfer-Encoding: chunked' (1 MiB body): 200 OK in ~1 ms where it previously hung.
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.
Problem
The
BodyType::Chunkedbranch (src/http/request.rs) read the raw stream in fixed 1024-byteread_exactblocks and never chunk-decoded it. With a finite payload the client keeps the connection open (keep-alive, no half-close), the final block never fills, and the server blocks forever instead of answering — hanging any chunked uploader after its first payload.Concrete case: librespeed/speedtest-cli#122 — librespeed-cli uploads at
0.55 Mbpsagainst librespeed-rs (one 1 MiB payload / 15 s duration). Same stall reproduces withcurl -H "Transfer-Encoding: chunked" --data-binary @file.See librespeed/speedtest-rust#49 for the full analysis (server log:
CHUNKED: read 1048837 raw bytes, then EOF/blocked— 1024×1024 payload + 261 bytes of chunk framing is not a multiple of the 1024-byte read block).Fix
Decode the chunked framing per RFC 9112 §7.1: read the chunk-size line (extensions after
;ignored), the chunk data, and the trailing CRLF per chunk; stop at the 0-size last chunk and consume the trailer section up to the blank line.Verification
cargo build --releasepasses.curl -H "Transfer-Encoding: chunked" --data-binary @1MiB→HTTP 200, 0.001s(previously hung);Content-Lengthuploads still work.23192 Mbpson loopback (was 0.55–1.61 Mbps).Closes #49