Skip to content

Commit

Permalink
fix x-forwarded-port header (#63303)
Browse files Browse the repository at this point in the history
Follow up to #61133 that will
rely on `x-forwarded-proto` value if it exists in order to default the
`x-forwarded-port` value.

Closes NEXT-2820
  • Loading branch information
Ethan-Arrowood authored Mar 18, 2024
1 parent 4064c64 commit b39a4d5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}

const { originalRequest } = req as NodeNextRequest
const isHttps = !!(originalRequest?.socket as TLSSocket)?.encrypted
const xForwardedProto = originalRequest?.headers['x-forwarded-proto']
const isHttps = xForwardedProto
? xForwardedProto === 'https'
: !!(originalRequest?.socket as TLSSocket)?.encrypted

req.headers['x-forwarded-host'] ??= req.headers['host'] ?? this.hostname
req.headers['x-forwarded-port'] ??= this.port
? this.port.toString()
Expand Down

0 comments on commit b39a4d5

Please sign in to comment.