Garrett Goebel wrote:
Geoffrey Young wrote:
 > > That's when you use Apache::compat, doing the mp1 syntax.
 > > In mp2-speak that would be:
 > >
 > >   $r->err_headers_out->add('Set-Cookie' => $packed_cookie);
 > >   $r->headers_out->set('Location' => $url);
 > >   $r->status(REDIRECT);
 > >
 > > notice that you don't need to call $r->send_http_header, it
 > > doesn't exist in mp2.
 >
 > not to mention it's entirely unnecessary (and undesirable) to
 > send headers on error responses such as redirects.

Why?

Appendix A.7 from the Stas' Practical mod_perl book states:

 > You should use err_headers_out( ), not headers_out( ),
 > when you want to send cookies in a REDIRECT response or
 > in any other non-2XX response

that's correct, but setting the headers is entirely different than sending them.



And gives the following recipe:


  Example A-3. redirect_cookie.pl
  use Apache::Constants qw(REDIRECT OK);
  my $r = shift;
  # prepare the cookie in $cookie
  $r->err_headers_out->add('Set-Cookie' => $cookie);
  $r->headers_out->set(Location => $location);
  $r->status(REDIRECT);
  $r->send_http_header;
  return OK;

How would you have written it?

the example is wrong - it should not have send_http_header() in it.


if you execute that script over telnet, you'll see two sets of headers.

apache automatically sends headers on errors - that's how you are able to get standard 500 pages, etc.


> and you should never set $r->status from a handler - for
> Registry scripts it's ok, since we use it as a hack to get
> around some things, but handlers should never manipulate the
> value of $r->status.


Why is that?

if r->status is not HTTP_OK (200) then apache thinks that an ErrorDocument has _also_ thrown an error, and it thus ends what would otherwise be a recursive cycle of errors. by messing with r->status, you mess up Apache's internal bookkeeping wrt the error document cycle.


--Geoff

/me sliently points to recipe 3.13 in the cookbook, too :)



--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to