I am currently programming a proxy server using httplib, and when I try to connect to HTTPS websites (such as facebook and google) my client sends me "CONNECT" requests that look like this:
CONNECT www.google.co.il:443 HTTP/1.1\r\n
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0\r\n
Proxy-Connection: keep-alive\r\n
Connection: keep-alive\r\n
Host: www.google.co.il:443\r\n
\r\n
I took a working proxy from the internet and put it on, then sniffed the network on wireshark, and the response to this request should look this way:
HTTP/1.1 200 Connection established\n
Proxy-agent: Python Proxy/0.1.0 Draft 1\n
\n
I noticed that the client sends the request to the proxy itself, so I decided to use socket, and send the response to the client in this way:
if getmethod(clientreq) is "CONNECT":
text="HTTP/1.1 200 Connection established\nProxy-Agent: THE BB Proxy\n\n"
client.send(text)
I really hoped that handling those "CONNECT" requests would be the solution and that my server will finally take care of HTTPS requests but it doesn't, and the response packets that I send to the client don't even appear on wireshark.
So my questions are: 1. What does the "CONNECT" method really do? 2. What else do I need except handling "CONNECT" method requests in order to communicate with a HTTPS servers?
CONNECT
essentially establishes a tunnel between the client and origin server. You will need to use I/O multiplexing (for example using theselect
module, or something like Twisted) to implement this correctly. – Rajab