'How to set up a https foward proxy for curl

I am facing one problem, and not get solution on google

I try to use curl to visit a https website behind a proxy but fail.

It is success without proxy or visit without ssl. Then I deployed a tcp proxy (got from https://github.com/kklis/proxy), and set enviroment export https_proxy=127.0.0.1:443

visit https://www.baidu.com, I just got connection aborted error

Here is how I run proxy:

./proxy -l 8111 -h www.baidu.com -p 443

And set proxy environment:

export https_proxy=127.0.0.1:8111

Run curl:

curl -v https://www.baidu.com

Got result:

Rebuilt URL to: https://www.baidu.com/

Trying 127.0.0.1...

Connected to 127.0.0.1 (127.0.0.1) port 8111 (#0)

Establish HTTP proxy tunnel to www.baidu.com:443

CONNECT www.baidu.com:443 HTTP/1.1

Host: www.baidu.com:443

User-Agent: curl/7.47.0

Proxy-Connection: Keep-Alive

Proxy CONNECT aborted

Connection #0 to host 127.0.0.1 left intact

curl: (56) Proxy CONNECT aborted

I tried add --insecure and not work, same result.

I think this is the same issue some one has met, still no answer: https://github.com/h2non/balboa/issues/1

Thanks if anyone can help!



Solution 1:[1]

I think I know the reason

I captured packets , using proxy to visit a https website , curl will start a HTTP CONNECT method to establish a tunnel. The tunnel should be between curl client and proxy, but TCP proxy will delivery all messages to web server, so web server will reset the connection.

A forward proxy should not just delivery messages between client and web server.It should understand the HTTP CONNECT method

I use a standard foward proxy - squid instead, then success.

Hope this helps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick