node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Changing changeOrigin to be true by default

Open patrickallaert opened this issue 8 years ago • 3 comments
trafficstars

As mentioned by @bdefore and @kdepp in #851, changeOrigin should be set to true by default.

The very first reason is simply to be compatible with the HTTP 1.1 specifications that requires a Host header. If a proxy listen on foobar.com and proxies request to bargee.net, then every requests sent to bargee.net must have a Host header set: Host: bargee.net. In turns, by fixing the inconsistencies generated by changeOrigin=false, it will enable all virtual host environment to serve request correctly. This is the case for example when using http-proxy via grunt-connect-proxy that even dropped support for changeOrigin and requires injecting forcefully the host header.

IMHO, it would even be better to get rid of that option completely and consider it is always true.

patrickallaert avatar Jan 19 '17 13:01 patrickallaert

here's specs rfc7230#section-5.4

raffy2010 avatar Mar 06 '18 07:03 raffy2010

Many users of this library (including me) encounter this problem and need to set changeOrigin: true:

https://stackoverflow.com/questions/14262986/node-js-hostname-ip-doesnt-match-certificates-altnames/45579167#45579167

Not far fetched to say some are just giving up before finding out about the changeOrigin flag.

oxygen avatar Aug 22 '18 10:08 oxygen

An approaching solution would be to improve the error message, to point to some documentation about this setting.

This is what I got:

[vite] http proxy error:
Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
    at TLSSocket.emit (node:events:394:28)
    at TLSSocket.emit (node:domain:475:12)
    at TLSSocket._finishInit (node:_tls_wrap:944:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12)

which is not very helpful to find the solution (changeOrigin: true)

oliverpool avatar Aug 19 '21 21:08 oliverpool