My understanding is that x-forwarded-port should be set to the server port that the request came in on: 80, 443, etc.
If that's the case, it's not happening. req.connection.remotePort is the requesting client's remote port. I didn't see an obvious way to get the server from the request, but it seems easy enough to determine it from the host header/protocol.
Assuming I'm understanding x-forwarded-port correctly, I've got a branch that fixes the issue here:
I have used x-forwarded-port with nginx; the expected value of the header is the port of the original request before it was proxied.
Say my node server is running on 3000 and is proxied by node-http-proxy on 3001.
I would like to know when crafting URLs for the original client that the public port is 3001.
At the moment node-http-proxy would give me something like 62112.
I have tested @blahed's patch and it works for me.
determine x-forwarded-port from host header
`req.remotePort' returns the ephemeral port, which is not useful.
node v0.10.0 added `req.localPort' which returns what we want, but
we want to maintain backwards compatibility. Fixes #341 & #227
I'm just coming across this now. I was wondering if there was a planned resolution, or something I missed?
Installing node v0.10.23 and node-http-proxy 0.10.3 shows the same behavior for me.
Edit: The caronte branch exhibits this behavior as well.
[fix] fixes #341
@fideloper fixed in 97e4600 :)