As I described in a previous question, I have an assignment to write a proxy server. It partially works now, but I still have a problem with handling of gzipped information.
You basically need to parse the response headers as text, and the rest as binary. It's slightly tricky to do so, as you can't just create an InputStreamReader
around the stream - that will read more data than you want. You'll quite possibly need to read data into a byte array and then call Encoding.GetString
manually. Alternatively, if you've read data into a byte array already you could always create a ByteArrayInputStream
around that, then an InputStreamReader
on top... but you'll need to work out how far the headers go before you get to the body of the response, which you should keep as binary data.