fix(http-proxy): decode chunked m3u responses#673
Merged
Conversation
Contributor
Documentation previewThe documentation preview has been deployed for this pull request. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes HTTP-proxy M3U rewriting when the upstream response uses Transfer-Encoding: chunked, by adding an incremental chunked-transfer decoder and decoding M3U bodies before URL rewriting while keeping non-M3U chunked responses on the existing passthrough path.
Changes:
- Added a standalone incremental HTTP chunked-transfer decoder (
http_chunked_decoder.*) and wired it into the M3U rewrite buffering path. - Implemented
Transfer-Encodingparsing to accept only supported chunked coding for M3U rewrites, strippingTransfer-Encoding/Trailerand emitting rewritten playlists with a correctContent-Length. - Updated e2e coverage to validate correct decoding, error handling for malformed chunked bodies, and robustness against upstream reset-after-send behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/http_proxy.h | Adds chunked-decoder state to the proxy session for chunked M3U rewrite handling. |
| src/http_proxy.c | Parses Transfer-Encoding, decodes chunked M3U bodies before rewrite, updates close/error handling to drain readable data first. |
| src/http_chunked_decoder.h | Declares the incremental chunked-transfer decoder API and state machine. |
| src/http_chunked_decoder.c | Implements chunk-size/trailer parsing and incremental decode/emit logic with bounds checks. |
| e2e/test_http_proxy_m3u_rewrite.py | Adds regression + negative tests for chunked M3U decode/rewrite behavior and upstream reset edge cases. |
| CMakeLists.txt | Includes the new decoder source in the build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Content-LengthRoot cause
The M3U rewrite path buffered the upstream response body without decoding HTTP chunk framing. Chunk-size lines and the terminating zero chunk were therefore treated as playlist content and rewritten as URLs.
Impact
Chunked HLS playlists are now decoded and rewritten correctly. Ordinary chunked responses continue through the existing raw passthrough path.
Validation
pnpm run lint:clanguv run ruff check e2ecmake --build build -j$(getconf _NPROCESSORS_ONLN)./scripts/run-e2e.sh -p 1 test_http_proxy_m3u_rewrite.py— 51 passed./scripts/run-e2e.sh -p 1 test_http_proxy.py— 19 passed./scripts/run-e2e.sh --co— 539 tests collectedgit diff --check