@@ -18,7 +18,10 @@ import { formatHostname } from '../format-hostname'
1818import { toNodeOutgoingHttpHeaders } from '../../web/utils'
1919import { isAbortError } from '../../pipe-readable'
2020import { getHostname } from '../../../shared/lib/get-hostname'
21- import { getRedirectStatus } from '../../../lib/redirect-status'
21+ import {
22+ getRedirectStatus ,
23+ allowedStatusCodes ,
24+ } from '../../../lib/redirect-status'
2225import { normalizeRepeatedSlashes } from '../../../shared/lib/utils'
2326import { getRelativeURL } from '../../../shared/lib/router/utils/relativize-url'
2427import { addPathPrefix } from '../../../shared/lib/router/utils/add-path-prefix'
@@ -657,15 +660,36 @@ export function getResolveRoutes(
657660
658661 if ( middlewareHeaders [ 'location' ] ) {
659662 const value = middlewareHeaders [ 'location' ] as string
660- const rel = getRelativeURL ( value , initUrl )
661- resHeaders [ 'location' ] = rel
662- parsedUrl = url . parse ( rel , true )
663663
664- return {
665- parsedUrl,
666- resHeaders,
667- finished : true ,
668- statusCode : middlewareRes . status ,
664+ // Only process Location header as a redirect if it has a proper redirect status
665+ // This prevents a Location header with non-redirect status from being treated as a redirect
666+ const isRedirectStatus = allowedStatusCodes . has (
667+ middlewareRes . status
668+ )
669+
670+ if ( isRedirectStatus ) {
671+ // Process as redirect: update parsedUrl and convert to relative URL
672+ const rel = getRelativeURL ( value , initUrl )
673+ resHeaders [ 'location' ] = rel
674+ parsedUrl = url . parse ( rel , true )
675+
676+ return {
677+ parsedUrl,
678+ resHeaders,
679+ finished : true ,
680+ statusCode : middlewareRes . status ,
681+ }
682+ } else {
683+ // Not a redirect: just pass through the Location header
684+ resHeaders [ 'location' ] = value
685+
686+ return {
687+ parsedUrl,
688+ resHeaders,
689+ finished : true ,
690+ bodyStream,
691+ statusCode : middlewareRes . status ,
692+ }
669693 }
670694 }
671695
0 commit comments