This is a toy program, play with it at your own risk. The HTTP proxy must support CONNECT method, and does not require authentication, or you could use HAProxy as backend. This program will drop any non-TCP traffic.
I copied lots of logic from fqrouter, its author is really smart!