HTTP question

S

slippymississippi

Just curious ... in a persistent HTTP connection, when receiving an
HTTP message with an attached body, how does one recognize the end of
the body?

Obviously, the start of the body is easy to parse for (CRLF followed by
CRLF), but is there a marker for the end of the body?
 
T

Thomas Fritsch

Just curious ... in a persistent HTTP connection, when receiving an
HTTP message with an attached body, how does one recognize the end of
the body?

Obviously, the start of the body is easy to parse for (CRLF followed by
CRLF), but is there a marker for the end of the body?
Then the HTTP message is required to have a header line like
  Content-Length: 12345
before the CRLFCRLF.
 
S

slippymississippi

Thomas said:
Then the HTTP message is required to have a header line like
Content-Length: 12345
before the CRLFCRLF.

Duh ... I knew I was forgetting something really stupid. Sorry for
lowering the bandwidth with something like this.
 
R

Rogan Dawes

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top