Practical mod_perl / HTML Book /



previous page: 16.2.1. Content-Type Header
  
page up: HTML Version of the book
  
next page: 16.2.3. Entity Tags

16.2.2. Content-Length Header


According to section 14.13 of the HTTP specification, the Content-Length header is the number of octets (8-bit bytes) in the body of a message. If the length can be determined prior to sending, it can be very useful to include it. The most important reason is that KeepAlive requests (when the same connection is used to fetch more than one object from the web server) work only with responses that contain a Content-Length header. In mod_perl we can write:

$r->header_out('Content-Length', $length);

When using Apache::File, the additional set_content_length( ) method, which is slightly more efficient than the above, becomes available to the Apache class. In this case we can write:

$r->set_content_length($length);

The Content-Length header can have a significant impact on caches by invalidating cache entries, as the following extract from the specification explains:

The response to a HEAD request MAY be cacheable in the sense that the information 
contained in the response MAY be used to update a previously cached entity from that 
resource.  If the new field values indicate that the cached entity differs from the 
current entity (as would be indicated by a change in Content-Length, Content-MD5, 
ETag or Last-Modified), then the cache MUST treat the cache entry as stale.

It is important not to send an erroneous Content-Length header in a response to either a GET or a HEAD request.

 

Continue to:

  • prev: 16.2.1. Content-Type Header
  • Table of Contents
  • next: 16.2.3. Entity Tags







TOP
previous page: 16.2.1. Content-Type Header
  
page up: HTML Version of the book
  
next page: 16.2.3. Entity Tags


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com