protocol-http icon indicating copy to clipboard operation
protocol-http copied to clipboard

When used with a proxy, CONNECT doesn't set an authority which causes it to send the wrong Host header

Open kamal opened this issue 2 years ago • 3 comments

I'm using Async::HTTP::Faraday with proxy to connect to a secure host. The proxy I'm using seems to be having trouble with the CONNECT request sent by the client. In particular, it relies on the Host header value to match the host we want to reach (not the proxy).

What it's sending to the proxy

CONNECT secure.host:443 HTTP/1.1
Host: proxy.host:80

I believe the correct form should be

CONNECT secure.host:443 HTTP/1.1
Host: secure.host:443

I tracked down why this was happening and it looks like the Protocol::HTTP::Methods#connect constructs a Request which only sets a few attributes, leaving authority as nil. When Async::HTTP::Client#call gets invoked, it then defaults the request.authority to the proxy's endpoint authority.

kamal avatar Sep 18 '23 23:09 kamal

Do you want to have a go at making a PR?

ioquatix avatar Oct 11 '23 00:10 ioquatix

@ioquatix sure I can whip up a PR. I wasn't sure if my conclusions were correct though.

kamal avatar Oct 12 '23 00:10 kamal

Let's start with a PR to see what exactly needs to change.

ioquatix avatar Oct 12 '23 00:10 ioquatix

You can now specify a custom authority using the authority: keyword argument: https://socketry.github.io/protocol-http/releases/index#request%5B%5D-and-response%5B%5D-keyword-arguments.

I don't know if this solves your problem as I think what you are drawing reference to is the default authority - feel free to clarify and re-open this issue or submit a PR.

ioquatix avatar Sep 05 '24 09:09 ioquatix