Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Where Content-Length starts?  RSS feed

 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HTTP response the length of attached entity is given by Content-Length?
For what? to determine the end? then how the start of attached entity is determined?
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by G Vanin:
In HTTP response the length of attached entity is given by Content-Length?
For what? to determine the end? then how the start of attached entity is determined?
Sometimes it's convenient for the receiving party to know how much data to expect.
And when you want to keep your connection for further requests (HTTP 1.1 keepalive) you must specify the content length, otherwise how can the receiving end know when the response has finished?
The start is, well, the start, the bit after the last end
- Peter
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mostly Content-Length is a convenience. However, when sending a PDF, it's pretty much mandatory - Netscape 4.7 would simply represent the document as empty (the Acrobat Reader got an error). The only way to "view" a PDF without a content-length was to download it and open it via Acrobat Reader as a local file.
The exact size of Content-Length is the precise byte count written to the output stream, That is the content and not the extraneous stuff like headers (cookies are headers, BTW). In servlet terms, that's everything written to the "out" stream.
Content-Length might also be critical if you're sending "chunked" Http output back, but this is a practice I prefer to avoid - at least for web-page content responses.
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter den Haan and Tim Holloway,
Originally posted by Peter den Haan:
The start is, well, the start, the bit after the last end

I am still unclear.
I understood that there status and headers before attached entity.
Some are optional headers.

Headers have variable/unpredictable content...
So, attached entity doesn't start after the end ... but where?
Might be status and headers are embedded inside fixed length envelopes or transmitted separately???
I donno, I am just a damned beginner.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The format of the response is:
<response code line><LF>
( <header-field><LF> ) *
<LF>
<response body>
The header is terminated by an empty line. The body is terminated either when Content-Length bytes have been read, or when the server closes the socket connection.
When you are coding a webserver there are many more details to worry about such as HTTP 1.1 keepalive (which can keep connections open) and chunked encoding (which allows a response to be broken up in chunks sent separately) but the principles broadly remain the same.
- Peter
[ January 02, 2003: Message edited by: Peter den Haan ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!