delvedor / hpagent

A ready to use http and https agent for working with proxies that keeps connections alive!
MIT License
181 stars 37 forks source link

Host header in proxy request seems to be wrong #25

Closed k-toumura closed 3 years ago

k-toumura commented 3 years ago

When issuing a request to a proxy, the Host header should contain the hostname and port of the destination URL (see RFC7231 Section 4.3.6), but the request issued by hpagent contain the hostname and port of the proxy.

For example, if the proxy address is proxy.example.com:8080 and the destination URL is https://destination.example.org/, the correct request would be:

CONNECT destination.example.org:443 HTTP/1.1
Host: destination.example.org:443

but hpagent issues the wrong request as follows:

CONNECT destination.example.org:443 HTTP/1.1
Host: proxy.example.com:8080

Suggestion for updates

To make hpagent gives the correct Host headers, update the hpagent's requestOptions (here and here) from:

      path: `${options.host}:${options.port}`,
      headers: { connection: this.keepAlive ? 'keep-alive' : 'close'},

to:

      path: `${options.host}:${options.port}`,
      setHost: false,
      headers: { connection: this.keepAlive ? 'keep-alive' : 'close', host: `${options.host}:${options.port}` },
hardillb commented 3 years ago

Hi @delvedor,

I appreciate you are likely busy, but if you have a moment to look at this and the linked pull request it would help us as we are using it as an upstream dependency for the next Node-RED release as we try and migrate from the request node.

Thanks.

mojavelinux commented 3 years ago

It seems like this issue was closed by #26.