feat(dev-server): support headers custom HTTP response headers (#143) - #183
Merged
lukekania merged 1 commit intoJun 8, 2026
Merged
Conversation
The dev-server `headers` option in angular.json was silently dropped, so apps relying on production-like security headers in dev (CSP, COOP) or testing CORS scenarios had no way to configure them. - `dev-server.json`: add `headers` (object of name to string value). - `serve/options.ts`: serialize the map into a `--headers` JSON arg, trimming names and dropping empty-name / non-string entries. - `serve_cmd.rs` / `main.rs`: parse the `--headers` JSON object and thread the name/value pairs into `DevServerConfig`. - `dev-server`: new `CustomHeaders` type applies the configured headers to every served response — static assets, the SPA-fallback index.html, and the SSE live-reload stream. Headers the server sets itself (`Content-Type`, `Cache-Control`, and the SSE-specific `Connection` / `Access-Control-Allow-Origin`) are never overridden. Headers are applied only in the Rust dev server, so proxy-forwarded responses keep their upstream headers untouched. Bump version to 0.10.15.
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.
Closes #143.
Goal
Support
angular.json's dev-serverheadersoption so projects can configure custom HTTP response headers in dev — production-like security headers (CSP,Cross-Origin-Opener-Policy), CORS headers, cache-control overrides, etc. Previously the option was silently dropped.Changes
packages/builder/schemas/dev-server.json— declareheadersas an object of header name to string value.packages/builder/src/serve/options.ts— serialize the map into a--headers '{...}'JSON arg, trimming header names and dropping empty-name / non-string entries.crates/cli/src/main.rs— add a--headersflag plusparse_header_overrides(), which rejects malformed JSON, non-objects, and non-string values with a clear error rather than dropping them silently.crates/cli/src/serve_cmd.rs— thread the parsed pairs intoDevServerConfig.crates/dev-server/— newCustomHeaderstype:warninstead of failing every request;index.html, and the SSE live-reload stream;Content-TypeandCache-Controlon files, plusConnection/Access-Control-Allow-Originon SSE.Headers are applied only in the Rust dev server, so proxy-forwarded responses keep their upstream headers untouched — no change needed in the Node proxy, which is transparent.
Definition of done
"headers": { "Cross-Origin-Opener-Policy": "same-origin" }results in the dev server emitting that header on every HTML/JS/asset response — covered by integration tests.Note on
Cache-ControlThe issue lists "cache-control overrides" as a motivating use case, but its Scope section says not to override headers the server sets itself. Live reload depends on
Cache-Control: no-cache, so a userCache-Controlentry is skipped (documented in code and the schema). Happy to revisit if overriding it is desired.Tests
Content-TypeandCache-Controlnot clobbered, multi-header, no-headers) + 6 newCustomHeadersunit tests.parse_header_overridescases.translateOptionsvitest cases.cargo clippy,tsc --noEmitclean; version bumped 0.10.14 → 0.10.15.