Unverified Commit fb119042 authored by Yuval Lotem's avatar Yuval Lotem Committed by GitHub

fix: x-forwarded-port header is 'undefined' when no port in url (#60484)

### What?
See this issue - https://github.com/vercel/next.js/issues/61133

following this change https://github.com/vercel/next.js/pull/57815
`x-forwarded-port` header value is 'undefined' if the URL has no port

### Why?
x-forwarded-port 'undefined' makes other http-proxy throw 405 error for
the invalid header value

### How?
Give default 80 port if the URL has no port

---------
Co-authored-by: 's avatarEthan Arrowood <ethan@arrowood.dev>
parent 5278d82a
......@@ -889,13 +889,15 @@ export default abstract class Server<ServerOptions extends Options = Options> {
)
}
req.headers['x-forwarded-host'] ??= req.headers['host'] ?? this.hostname
req.headers['x-forwarded-port'] ??= this.port?.toString()
const { originalRequest } = req as NodeNextRequest
req.headers['x-forwarded-proto'] ??= (originalRequest.socket as TLSSocket)
?.encrypted
? 'https'
: 'http'
const isHttps = !!(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()
: isHttps
? '443'
: '80'
req.headers['x-forwarded-proto'] ??= isHttps ? 'https' : 'http'
req.headers['x-forwarded-for'] ??= originalRequest.socket?.remoteAddress
// This should be done before any normalization of the pathname happens as
......
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