fix: respect wasm-set Cache-Control and CORS response headers#131
Open
fix: respect wasm-set Cache-Control and CORS response headers#131
Conversation
Replace HeaderMap::extend with entry().or_insert_with() so the runtime defaults (Access-Control-Allow-Origin: *, Cache-Control: no-store) fill only when the wasm component does not set them. Per-app `rsp_headers` config still wins over both wasm and defaults. Previously the defaults were unconditionally appended, producing duplicate Cache-Control values; per RFC 9111 the more restrictive directive (no-store) then silently overrode any cache-control the JS handler returned. Adds 6 unit tests covering the new precedence: default fills when wasm silent, wasm-set values are preserved, per-app config replaces wasm value, custom app headers, empty-value no-op. Existing executor::http tests pass unchanged — their wasm fixtures don't set those headers, so defaults still kick in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
crates/http-service/src/lib.rswas usingHeaderMap::extendto merge runtime defaults onto the wasm component's response.extendappends, so a JS handler returningCache-Control: public, max-age=60ended up with both that value and the runtime'sCache-Control: no-storeon the wire — and per RFC 9111 the more restrictive directive wins, silently overriding the developer's intent. Same hazard forAccess-Control-Allow-Origin: *.This PR turns the runtime's
*andno-storefrom forced-overrides into actual defaults viaHeaderMap::entry().or_insert_with(), applied in-place on the response headers. Per-app staticrsp_headersconfig still takes precedence over both.New precedence
app_cfg.rsp_headers(operator) > wasm response (developer) > runtime defaultWhy the defaults exist at all
Both
Access-Control-Allow-Origin: *andCache-Control: no-storeshipped with the very first commit (2fbda12, 2024-05-07) — no commit-message rationale, no in-source comment, untouched in 4 follow-up refactors. Best inference:*is the*.fastedge.appproduct default for browseable origins;no-storeis "safe by default" for dynamic edge compute. Both defensible as defaults, never re-evaluated as forced overrides. This PR keeps them as defaults.Error-path reserved header
Reordered the error-response builder so
X_CDN_INTERNAL_STATUSis forciblyinserted afterapply_default_and_app_headers. Previously, an app config that mappedrsp_headers["x-cdn-internal-status"]would replace the genuine FastEdge error code (timeout/OOM/execute-error) in the helper's loop. The reserved internal status now always wins on error responses.Tests
test_success,test_timeout,test_insufficient_memory,test_success_with_fastedge_app_id) pass unchanged — their wasm fixtures don't setCache-Control/Access-Control-Allow-Origin, so the defaults still kick in.apply_default_and_app_headerscovering: defaults fill when wasm silent, wasm-set values are preserved (no append-duplicates), per-app config replaces wasm value, custom app headers, empty-value no-op, reserved internal status cannot be spoofed byrsp_headers.Migration note
Apps that already set
Cache-ControlorAccess-Control-Allow-Originfrom JS will start having those values honored. Apps that don't set them still get the sameno-store/*defaults as before.Test plan
cargo test -p http-servicecargo test -p http-service --features metricscargo clippy -p http-service --all-targets— no new warnings (one pre-existinglet_and_returnatexecutor/http.rs:259unrelated to this PR)cargo fmt -p http-serviceCache-Control: public, max-age=60to a JS handler, confirm value lands in the response headers withoutno-storesiblings.🤖 Generated with Claude Code