MCPcopy Index your code
hub / github.com/angular/angular-cli / createRedirectResponse

Function createRedirectResponse

packages/angular/ssr/src/utils/redirect.ts:35–73  ·  view source on GitHub ↗
(
  location: string,
  status = 302,
  headers?: Record<string, string> | Headers,
)

Source from the content-addressed store, hash-verified

33 * @returns A `Response` object representing the HTTP redirect.
34 */
35export function createRedirectResponse(
36 location: string,
37 status = 302,
38 headers?: Record<string, string> | Headers,
39): Response {
40 if (ngDevMode && !isValidRedirectResponseCode(status)) {
41 throw new Error(
42 `Invalid redirect status code: ${status}. ` +
43 `Please use one of the following redirect response codes: ${[...VALID_REDIRECT_RESPONSE_CODES.values()].join(', ')}.`,
44 );
45 }
46
47 const resHeaders = headers instanceof Headers ? headers : new Headers(headers);
48 if (ngDevMode && resHeaders.has('location')) {
49 // eslint-disable-next-line no-console
50 console.warn(
51 `Location header "${resHeaders.get('location')}" will be ignored and set to "${location}".`,
52 );
53 }
54
55 // Ensure unique values for Vary header
56 const varyArray = resHeaders.get('Vary')?.split(',') ?? [];
57 const varySet = new Set(['X-Forwarded-Prefix']);
58 for (const vary of varyArray) {
59 const value = vary.trim();
60
61 if (value) {
62 varySet.add(value);
63 }
64 }
65
66 resHeaders.set('Vary', [...varySet].join(', '));
67 resHeaders.set('Location', location);
68
69 return new Response(null, {
70 status,
71 headers: resHeaders,
72 });
73}

Callers 4

redirect_spec.tsFile · 0.90
handleMethod · 0.90
handleRenderingMethod · 0.90

Calls 7

hasMethod · 0.65
warnMethod · 0.65
getMethod · 0.65
valuesMethod · 0.45
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected