So I came across a question on stackoverflow regarding implementing an HTTP proxy server. This was a project I had to do while studying computer science at the University of Kentucky several years ago. It was a project I had enjoyed and I thought it would be fun to re-implement a proxy server in C#. So I spent a Sunday afternoon and built a nice little multi-threaded proxy server complete with caching!
HTTPS – To tunnel or not to tunnel
Normally when a browser needs to request an https uri it will still interact with a proxy server by issuing a CONNECT request to the proxy server. This request tells the proxy server to establish a tunnel from the client to the destination server and relay traffic across the respective connections. Since the proxy server will only be dealing with TCP level traffic to handle this tunnel, the communication can still be secured between the client and the server. Well, this was all too easy and I wanted a challenge of creating an https debugging proxy like Fiddler, which is one of the most useful tools there is for a web software developer like myself.
To do the heavy lifting of the SSL protocol (in one line of code) I used the System.Net.Security.SslStream class which made the project super simple. I’ll spare the details of the implementation because i posted an article on CodeProject.com
So I had fun writing this little program and reminiscing about my networking class in college. Actually the thing performs pretty well when not dumping data and is fun to play with. I might actually use it to do some http debugging instead of fiddler in the future as it is a quick easy interface from the command line. With the caching that I implemented, just running it locally for myself provides some pretty speedy pages when caching is allowed.
You can find the source and executable over on the code project article, but I have also included the source here
in my SkyDrive. Let me know what you think!