fix `x-forwarded-port` header (#63303)

Follow up to https://github.com/vercel/next.js/issues/61133 that will
rely on `x-forwarded-proto` value if it exists in order to default the
`x-forwarded-port` value.

Closes NEXT-2820
parent 5b16b599
...@@ -914,7 +914,11 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -914,7 +914,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} }
const { originalRequest } = req as NodeNextRequest 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-host'] ??= req.headers['host'] ?? this.hostname
req.headers['x-forwarded-port'] ??= this.port req.headers['x-forwarded-port'] ??= this.port
? this.port.toString() ? this.port.toString()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment