Hi,

Am Samstag 31 Juli 2004 10:20 schrieb Stas Bekman:
> Geoffrey Young wrote:
> > Boris Zentner wrote:
> >>Hi,
> >>
> >>I have a handler, that serve dynamic pages or static ones. If the handler
> >> gets a HEAD request, it answers with
>
> [...]
>
> > it is desired - you no longer need to set the Content-Length header for
> > requests in Apache 2.0.
>
> It's somewhat documented:
> http://perl.apache.org/docs/2.0/user/handlers/http.html#Handling_HEAD_Reque
>sts
>

I just read it, thanks for the pointer. I think the text should make clear, 
that even if it is not needed to return early with 'return OK if 
$r->header_only;' with apache2, it is recommended, since it is ( or can be ) 
a big waste of time to construct the body, that is removed in the next pass.

From reading the comments in modules/http/http_protocol.c 
( ap_http_header_filter ), I get the impression, that apache2 recommend 
generating and throwing away the content. Here is the comment in question:

    /* This is a hack, but I can't find anyway around it.  The idea is that
     * we don't want to send out 0 Content-Lengths if it is a head request.
     * This happens when modules try to outsmart the server, and return
     * if they see a HEAD request.  Apache 1.3 handlers were supposed to
     * just return in that situation, and the core handled the HEAD.  In
     * 2.0, if a handler returns, then the core sends an EOS bucket down
     * the filter stack, and the content-length filter computes a C-L of
     * zero and that gets put in the headers, and we end up sending a
     * zero C-L to the client.  We can't just remove the C-L filter,
     * because well behaved 2.0 handlers will send their data down the stack,
     * and we will compute a real C-L for the head request. RBB
     */

also The comment implies, that I get a Content-Length header for a HEAD 
request, if I waste my time and generate the body of the message. I tried it 
and got _no_ Content-Length header!

 $apr->content_type($media_type) unless $apr->main;
  if ( $apr->header_only ) {
    $apr->print( ' ' x $size ); # just to see if I got a content-length header
    return DONE;
  }

The only way to get the Content-Length header for a HEAD request is 

 $apr->headers_out->{'Content-Length'} = $size ;
 $apr->content_type($media_type) unless $apr->main;
  if ( $apr->header_only ) {
    $apr->rflush;
    return DONE;
  }

But I fail to see why this works, I thought the data walks the same filter 
chain only in more buckets.

I used 

Server: Apache/2.0.49 (Unix) mod_perl/1.99_14 Perl/v5.8.3 mod_ssl/2.0.49 
OpenSSL/0.9.7d DAV/2 SVN/1.0.2

> > basically, any C-L header you set in the content-generation phase of the
> > request has the potential to be incorrect, since any filter can come
> > along and alter the content.  so, what apache does is it runs the new
> > content-length filter, which will decide whether a C-L header is required
> > and take appropriate steps.  for instance, apache will abandon the C-L
> > header if it decides it can use a chunked transfer encoding instead.
>
> Geoff, feel free to improve that section to be more complete. Thanks.
>

-- 
Boris

--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to