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.
After reading the headers with BufferedReader
you'll need to detect if the Content-Encoding
header is set to gzip
. If it is, to read the body you'll have to switch to using the InputStream
and wrap it with a GZIPInputStream
to decode the body. The tricky part however is the fact that the BufferedReader
will have buffered past the headers into the body and the underlying InputStream
will be ahead of where you need it.
What you could do is wrap the initial InputStream
with a BufferedInputStream
and call mark()
on it before you begin processing the headers. When you're done processing the headers call reset()
. Then read that stream until you hit the empty line between headers and the body. Now wrap it with the GZIPInputStream
to process the body.