Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

HTTP question

Thread view: 
slippymississippi@yahoo.com - 27 Jun 2006 18:02 GMT
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?
Thomas Fritsch - 27 Jun 2006 18:15 GMT
> 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.

Signature

"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')

slippymississippi@yahoo.com - 27 Jun 2006 21:58 GMT
> > Just curious ... in a persistent HTTP connection, when receiving an
> > HTTP message with an attached body, how does one recognize the end of
[quoted text clipped - 5 lines]
>   Content-Length: 12345
> before the CRLFCRLF.

Duh ... I knew I was forgetting something really stupid.  Sorry for
lowering the bandwidth with something like this.
Rogan Dawes - 28 Jun 2006 08:03 GMT
>>> Just curious ... in a persistent HTTP connection, when receiving an
>>> HTTP message with an attached body, how does one recognize the end of
[quoted text clipped - 8 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.