{"record":{"id":"6fa7d809f1d34e74","repo":"angular/angular-cli","slug":"location-header-resheaders-get-location-wi","errorCode":null,"errorMessage":"Location header \"${resHeaders.get('location')}\" will be ignored and set to \"${location}\".","messagePattern":"Location header \"(.+?)\" will be ignored and set to \"(.+?)\"\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/angular/ssr/src/utils/redirect.ts","lineNumber":50,"sourceCode":" * @param headers - Additional headers to include in the response.\n * @returns A `Response` object representing the HTTP redirect.\n */\nexport function createRedirectResponse(\n  location: string,\n  status = 302,\n  headers?: Record<string, string> | Headers,\n): Response {\n  if (ngDevMode && !isValidRedirectResponseCode(status)) {\n    throw new Error(\n      `Invalid redirect status code: ${status}. ` +\n        `Please use one of the following redirect response codes: ${[...VALID_REDIRECT_RESPONSE_CODES.values()].join(', ')}.`,\n    );\n  }\n\n  const resHeaders = headers instanceof Headers ? headers : new Headers(headers);\n  if (ngDevMode && resHeaders.has('location')) {\n    // eslint-disable-next-line no-console\n    console.warn(\n      `Location header \"${resHeaders.get('location')}\" will be ignored and set to \"${location}\".`,\n    );\n  }\n\n  // Ensure unique values for Vary header\n  const varyArray = resHeaders.get('Vary')?.split(',') ?? [];\n  const varySet = new Set(['X-Forwarded-Prefix']);\n  for (const vary of varyArray) {\n    const value = vary.trim();\n\n    if (value) {\n      varySet.add(value);\n    }\n  }\n\n  resHeaders.set('Vary', [...varySet].join(', '));\n  resHeaders.set('Location', location);\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/ssr/src/utils/redirect.ts#L32-L68","documentation":"`createRedirectResponse` builds a redirect with a computed `location` (e.g. from Accept-Language negotiation). If the caller-supplied headers already contain a `location` header, it would be overwritten, so in dev mode (`ngDevMode`) the engine warns that the original Location value is ignored and replaced.","triggerScenarios":"Calling `createRedirectResponse` (directly or via `redirectBasedOnAcceptLanguage`, interceptors/handlers that produce redirect responses) with a `Headers` object that already has `location` set while `ngDevMode` is true.","commonSituations":"Manually adding a Location header in a server interceptor and also using locale-based redirects; middleware setting redirects that conflict with the framework's computed redirect target.","solutions":["Remove the `location` entry from the headers you pass to `createRedirectResponse` and let the function compute it.","If you need a custom target, use the API's dedicated location/target parameter instead of pre-setting the header.","Silence in production is automatic (ngDevMode only), but fix the duplicate for correctness regardless."],"exampleFix":"// before\nconst headers = new Headers({ location: '/custom' });\ncreateRedirectResponse(request, headers, 302);\n// after\nconst headers = new Headers();\ncreateRedirectResponse(request, headers, 302); // location computed by the API","handlingStrategy":"validation","validationCode":"// ensure no pre-set location header before creating a redirect\nconst h = headers instanceof Headers ? headers : new Headers(headers);\nif (h.has('location')) throw new Error('Strip location header; createRedirectResponse sets it.');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass redirect target via the API's location parameter, not raw headers.","Sanitize incoming Headers objects by deleting `location` before redirect construction.","Run SSR dev mode (ngDevMode) tests to catch duplicate-location conflicts early."],"tags":["ssr","redirect","headers","dev-mode"],"backgroundTag":"duplicate-location-header","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}