Skip to content
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

got 407 when fetching https with downstream proxy #269

Open
skiloop opened this issue Sep 30, 2018 · 2 comments
Open

got 407 when fetching https with downstream proxy #269

skiloop opened this issue Sep 30, 2018 · 2 comments

Comments

@skiloop
Copy link

skiloop commented Sep 30, 2018

My remote proxy which is password protected and supports https, when applies to martian as downstream proxy, 407 is got.

martian -addr=:8000 -api martian -organization Martian -downstream-proxy-url http://xxxx:password@someproxy:60000
curl -x http://localhost:8000 https://ip.cn  -v

then comes the following result:

  • Rebuilt URL to: https://ip.cn/
  • Trying ::1...
  • TCP_NODELAY set
  • Connected to localhost (::1) port 8000 (#0)
  • allocate connect buffer!
  • Establish HTTP proxy tunnel to ip.cn:443

CONNECT ip.cn:443 HTTP/1.1
Host: ip.cn:443
User-Agent: curl/7.59.0
Proxy-Connection: Keep-Alive

< HTTP/1.1 407 Proxy Authentication Required
< Connection: close
< Content-Type: text/html
< Server: someproxy
<

  • Received HTTP code 407 from proxy after CONNECT
  • CONNECT phase completed!
  • Closing connection 0
    curl: (56) Received HTTP code 407 from proxy after CONNECT
@skiloop
Copy link
Author

skiloop commented Sep 30, 2018

after monitor network traffic, I found not Proxy-Authorization in headers fields of the CONNECT method to downstream proxy.
I changed a few lines of function Proxy.connect to:

		pbw := bufio.NewWriter(conn)
		pbr := bufio.NewReader(conn)
		if p.proxyURL.User != nil {
			req.Header.Add("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(p.proxyURL.User.String())))
		}
		req.Write(pbw)
		pbw.Flush()

and this results stucking at tls handshakes

@skiloop
Copy link
Author

skiloop commented Oct 8, 2018

The problem may be the usage of http.ReadResponse for CONNECT

res, err := http.ReadResponse(pbr, req)

When it write response back, "Connection: close" is added automatically.

skiloop added a commit to skiloop/martian that referenced this issue Oct 8, 2018
skiloop added a commit to skiloop/martian that referenced this issue Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant