qwj / python-proxy

HTTP/HTTP2/HTTP3/Socks4/Socks5/Shadowsocks/ShadowsocksR/SSH/Redirect/Pf TCP/UDP asynchronous tunnel proxy implemented in Python 3 asyncio.
MIT License
1.93k stars 323 forks source link

Obey RFC2616 in CONNECT request #151

Closed Mervent closed 5 months ago

Mervent commented 2 years ago

Some proxy servers requires Host header to be the same as CONNECT or they will return 400 http code on request.

RFC2616 tells us the same thing

https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that >identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad >Request) status code to any HTTP/1.1 request message which lacks a Host header field.

Before the change

CONNECT ifconfig.co:443 HTTP/1.1
Host: PROXY_IP
Proxy-Authorization: Basic --base64data--

After the change

CONNECT ifconfig.co:443 HTTP/1.1
Host: ifconfig.co:443
Proxy-Authorization: Basic --base64data--
Mervent commented 2 years ago

Proper usage of CONNECT method is also described in updated RFC7231 https://httpwg.org/specs/rfc7231.html#CONNECT