Your proxy reminds me of a project of mine from a few years ago called Protoscope. At the time, the sockets extension was so volatile that I wouldn't be surprised if it no longer works. You can glance through the source here:
If I recall correctly, it handles chunked responses and a lot of little details like that, but it's still not very robust and was never truly completed. It's nice to see that the same idea has arisen again.