Skip to content

fix(@angular/ssr): support custom headers in redirect responses [20]#32779

Merged
dgp1130 merged 3 commits intoangular:20.3.xfrom
alan-agius4:prefix-url-20
Mar 17, 2026
Merged

fix(@angular/ssr): support custom headers in redirect responses [20]#32779
dgp1130 merged 3 commits intoangular:20.3.xfrom
alan-agius4:prefix-url-20

Conversation

@alan-agius4
Copy link
Collaborator

No description provided.

Updated the INVALID_PREFIX_REGEX to ensure that prefixes starting with a backslash are considered invalid. Previously, only multiple slashes or dot segments were explicitly disallowed at the start.

Also updated the associated validation error message and unit tests to reflect this change.
@alan-agius4 alan-agius4 requested a review from dgp1130 March 17, 2026 10:05
@alan-agius4 alan-agius4 added the target: lts This PR is targeting a version currently in long-term support label Mar 17, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the createRedirectResponse function into its own utility file packages/angular/ssr/src/utils/redirect.ts and enhances it to support custom headers in redirect responses. The changes are well-structured and include corresponding updates to call sites and new tests. I've found a small issue with how the Vary header is being constructed which could lead to duplicate values. My suggestion addresses this to make the logic more robust.

Updates createRedirectResponse to accept an optional Record<string, string> of headers, allowing custom headers to be merged into the redirect response. The Location and Vary: X-Forwarded-Prefix headers are automatically set to ensure correct routing and proxy behavior.

AngularServerApp now passes relevant headers from the matched route or response context when creating a redirect.
Refactors the `createRedirectResponse` function to use a `Set` for constructing the `Vary` header. This ensures that `X-Forwarded-Prefix` is always present exactly once, and that existing `Vary` values from provided headers are correctly parsed, deduplicated, and preserved.

Updates the associated unit tests to reflect the new header order and verify the deduplication logic.
@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Mar 17, 2026
@dgp1130 dgp1130 merged commit 0a2ff0b into angular:20.3.x Mar 17, 2026
32 of 33 checks passed
@dgp1130
Copy link
Collaborator

dgp1130 commented Mar 17, 2026

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr target: lts This PR is targeting a version currently in long-term support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants