Phase 4: Stream binary pass-through responses via io::copy#594
Open
aram356 wants to merge 5 commits intofeature/streaming-pipeline-phase3from
Open
Phase 4: Stream binary pass-through responses via io::copy#594aram356 wants to merge 5 commits intofeature/streaming-pipeline-phase3from
aram356 wants to merge 5 commits intofeature/streaming-pipeline-phase3from
Conversation
Non-processable 2xx responses (images, fonts, video) now stream directly to the client via PublisherResponse::PassThrough instead of buffering the entire body in memory. Content-Length is preserved since the body is unmodified.
Tests verify non-processable 2xx responses return PassThrough, non-processable errors stay Buffered, and processable content goes through Stream (not PassThrough).
Adds pass_through_preserves_body_and_content_length test that verifies io::copy produces identical output and Content-Length is preserved. Updates handle_publisher_request doc to describe all three response variants.
- Exclude 204 No Content from PassThrough (must not have body) - Remove Content-Length before streaming (stream_to_client uses chunked encoding, keeping both violates HTTP spec) - Add tests for 204 exclusion and empty-host interaction - Update doc comment and byte-level test to reflect CL removal
PassThrough reattaches the unmodified body and uses send_to_client() instead of stream_to_client() + io::copy. This preserves Content-Length (avoids chunked encoding overhead for images/fonts) and lets Fastly stream from its internal buffer without WASM memory buffering.
This was
linked to
issues
Mar 27, 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
Stream non-processable 2xx responses (images, fonts, video) directly to the client instead of buffering the entire body in memory. Uses
send_to_client()with the unmodified body to preserveContent-Lengthand avoid chunked encoding overhead.Closes #592, closes #593.
Part of epic #563. Depends on Phase 3 (#591).
Performance results (staging vs production, median over 8 runs, Chrome 1440x900)
Measured on getpurpose.ai via Chrome DevTools Protocol with
--host-resolver-rulesto route to staging Fastly edge.How it works
The streaming gate in
handle_publisher_requestnow has three outcomes:PassThroughreattaches the unmodified body and sends viasend_to_client(), preservingContent-Length. This avoids both WASM memory buffering and chunked encoding overhead.What changed
publisher.rsPassThroughvariant, gate logic, 204 exclusion, testsmain.rsPassThrough: reattach body, return forsend_to_client()Tests added
pass_through_gate_streams_non_processable_2xx— images/fonts return PassThroughpass_through_gate_buffers_non_processable_error— 4xx stays Bufferedpass_through_gate_does_not_apply_to_processable_content— HTML goes through Streampass_through_gate_excludes_204_no_content— 204 stays Buffered (HTTP spec)pass_through_gate_applies_with_empty_request_host— empty host still passes throughpass_through_preserves_body_and_content_length— byte-for-byte identity + CL preservedVerification
cargo test --workspace— 772 passed, 0 failedcargo clippy --workspace --all-targets --all-features -- -D warnings— cleancargo fmt --all -- --check— cleancargo build --release --target wasm32-wasip1— successTest plan