Implementing an HTTP proxy

9.9k views Asked by At

I would like to implement and HTTP proxy server to get a deeper understanding of some of the finer points of the protocol and learn some socket programming along the way but I don't want to implement a full-blown HTTP server. What are the relevant RFC pages and sections in those pages that I should be focusing on if I just want to implement a proxy?

The plan is to start with a regular HTTP proxy and then potentially extend it to an HTTPS proxy.

3

There are 3 answers

1
SameOldNick On BEST ANSWER
3
strongwillow On

I'm currently working on it too. The basic implementation is simple. Listen on a socket port, find the host, connect to remote server, send http header, recv from server, then send back to client. The difficult part is consistent connection and pipelining.

As to HTTPs, its header is like this:

CONNECT addons.mozilla.org:443 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0
Host: addons.mozilla.org

Proxy should connect to server, then reply to client a 200 message, then redirect back and forth as a redirector.

Check this: https://datatracker.ietf.org/doc/html/draft-luotonen-ssl-tunneling-03

0
Mark Nottingham On

You might also find the work of the HTTPbis group in the IETF helpful; we're re-writing the specs to make them more clear and easier to implement.

See http://trac.tools.ietf.org/wg/httpbis/trac/wiki for more information.