Duh ... I knew I was forgetting something really stupid. Sorry for
lowering the bandwidth with something like this.
In fact, this is not strictly true.
The response can be sent as a Chunked encoded stream, where the chunk
size is written one one line, followed by that many bytes, followed by
another chunk size, etc. The stream ends when the chunk size is 0, BUT,
can be followed by another set of headers (footers).
The response size can also be indicated by closing the stream when the
last bytes are written. Obviously, this is not very robust, and not good
for performance, but it is very simple to implement.
I'd suggest reading the HTTP RFC's. 2616 is a good place to start.
However, one has to ask why you are implementing your own HTTP user agent.
There are a number of existing client libraries out there. e.g. Apache
Commons HttpClient, that do the job VERY well, and have been thoroughly
debugged. I've written my own user-agent which has been in use for about
3 years, (hence I know all the details above), and I have given up on it
and gone over to the Apache client.
Rogan