• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where Content-Length starts?

 
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic