-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: allow customizing proxy CONNECT url #45460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
@seankhliao Oh no, I'm sorry that I didn't express it clearly. I read the relevant code and did not find a way to customize the CONNECT request. Perhaps this requires a new API. |
what exactly do you want to do? change the address the of the proxy while keeping the hostname? |
When an HTTPS request is sent through an HTTP proxy, it will first send a CONNECT request to establish a TCP connection, and then it will start a handshake with the SSL of the website. If a website has multiple resolution addresses, such as using a CDN, you can use the specified backend IP to access the website by specifying the CONNECT URL. I hope there is an API that can customize the CONNECT URL or customize the entire CONNECT request. |
Right, different values for |
The code that sets up the CONNECT does:
If hdr["Host"] is set, then it sounds like we should use it instead of cm.targetAddr to set up connectReq.Host. That is, add:
Does anyone have any objections to this? |
This proposal has been added to the active column of the proposals project |
Sorry but I am confused on what we are trying to solve. We have a request to some target site, www.target.org, and we are going through some Proxy. The actual request has a URL/host of www.target.org. It really doesn't matter what the host header is. The Request will ignore the Host header and generate its own based, https://github.com/golang/go/blob/master/src/net/http/request.go#L570 A proxy is required to ignore the host header if it receives an absolute uri, https://tools.ietf.org/html/rfc7230#section-5.4
|
@fraenkel, that's for a standard HTTP proxy, not for some custom thing serving CONNECT requests. |
@rsc sorry my bad. |
Probably easier to rewrite the url since the host is only used of there is no opaque bit in the url. |
Sorry I confused myself again. Ignore what I said. I need to double check my test case which didn't see the host header on the other side. |
I forgot that ReadRequest deletes the host header. So as long as the other side isn't using Go, this should work. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/431756 mentions this issue: |
I don't believe this is correct. RFC 9110 9.3.6 states that a proxy should connect to the "server identified by the request target". It doesn't say anything about the I did find a 2009 ietf-http-wg thread discussing the role of the That said, the general idea of setting the target of the proxy request via the proxy connect headers seems reasonable; we should just set both the request target and the host header. |
Update May 5 2021: The current proposed API is in #45460 (comment) - rsc
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I want to use a proxy to access HTTPS websites and customize the backend IP address
What did you expect to see?
Is there some way to customize the URL of the CONNECT request
What did you see instead?
Both CONNECT request and SSL handshake use
cm.targetAddr
go/src/net/http/transport.go
Lines 1667 to 1672 in 2ebe77a
go/src/net/http/transport.go
Lines 1725 to 1729 in 2ebe77a
go/src/net/http/transport.go
Lines 1838 to 1846 in 2ebe77a
The text was updated successfully, but these errors were encountered: