Skip to content

Commit 34753d1

Browse files
committed
refactor: remove X-Forwarded-Prefix from Vary header in SSR redirect utility
This is no longer needed since now `X-Forwarded-Prefix` is validated by the users.
1 parent 126b19b commit 34753d1

3 files changed

Lines changed: 2 additions & 32 deletions

File tree

packages/angular/ssr/src/utils/redirect.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ export function createRedirectResponse(
5050
);
5151
}
5252

53-
// Ensure unique values for Vary header
54-
const varyArray = resHeaders.get('Vary')?.split(',') ?? [];
55-
const varySet = new Set(['X-Forwarded-Prefix']);
56-
for (const vary of varyArray) {
57-
const value = vary.trim();
58-
59-
if (value) {
60-
varySet.add(value);
61-
}
62-
}
63-
64-
resHeaders.set('Vary', [...varySet].join(', '));
6553
resHeaders.set('Location', location);
6654

6755
return new Response(null, {

packages/angular/ssr/test/app-engine_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe('AngularAppEngine', () => {
160160
const response = await appEngine.handle(request);
161161
expect(response?.status).toBe(302);
162162
expect(response?.headers.get('Location')).toBe('/it');
163-
expect(response?.headers.get('Vary')).toBe('X-Forwarded-Prefix, Accept-Language');
163+
expect(response?.headers.get('Vary')).toBe('Accept-Language');
164164
});
165165

166166
it('should include forwarded prefix in locale redirect location when present', async () => {
@@ -174,7 +174,7 @@ describe('AngularAppEngine', () => {
174174
const response = await appEngine.handle(request);
175175
expect(response?.status).toBe(302);
176176
expect(response?.headers.get('Location')).toBe('/app/it');
177-
expect(response?.headers.get('Vary')).toBe('X-Forwarded-Prefix, Accept-Language');
177+
expect(response?.headers.get('Vary')).toBe('Accept-Language');
178178
});
179179

180180
it('should completely ignore proxy headers if not allowed', async () => {

packages/angular/ssr/test/utils/redirect_spec.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ describe('Redirect Utils', () => {
1414
const response = createRedirectResponse('/home');
1515
expect(response.status).toBe(302);
1616
expect(response.headers.get('Location')).toBe('/home');
17-
expect(response.headers.get('Vary')).toBe('X-Forwarded-Prefix');
1817
});
1918

2019
it('should create a redirect response with a custom status', () => {
@@ -27,23 +26,6 @@ describe('Redirect Utils', () => {
2726
const response = createRedirectResponse('/home', 302, { 'X-Custom': 'value' });
2827
expect(response.headers.get('X-Custom')).toBe('value');
2928
expect(response.headers.get('Location')).toBe('/home');
30-
expect(response.headers.get('Vary')).toBe('X-Forwarded-Prefix');
31-
});
32-
33-
it('should append to Vary header instead of overriding it', () => {
34-
const response = createRedirectResponse('/home', 302, {
35-
'Location': '/evil',
36-
'Vary': 'Host',
37-
});
38-
expect(response.headers.get('Location')).toBe('/home');
39-
expect(response.headers.get('Vary')).toBe('X-Forwarded-Prefix, Host');
40-
});
41-
42-
it('should NOT add duplicate X-Forwarded-Prefix if already present in Vary header', () => {
43-
const response = createRedirectResponse('/home', 302, {
44-
'Vary': 'X-Forwarded-Prefix, Host',
45-
});
46-
expect(response.headers.get('Vary')).toBe('X-Forwarded-Prefix, Host');
4729
});
4830

4931
it('should warn if Location header is provided in extra headers in dev mode', () => {

0 commit comments

Comments
 (0)