Title: FW: $r->headers_out Location and Set-Cookie
[Note: reposting, the original post appears to have dropped through the cracks]
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
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?
> 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?
--
Garrett Goebel
IS Development Specialist
ScriptPro Direct: 913.403.5261
5828 Reeds Road Main: 913.384.1008
Mission, KS 66202 Fax: 913.384.2180
www.scriptpro.com garrett at scriptpro dot com