Re: $r->headers_out Location and Set-Cookie
On Fri, Sep 05, 2003 at 10:13:36, Geoffrey Young said... > actually, the return value is entirely ignored in Registry scripts - that's > why we need the $r->status hack, which is not needed (or desired) in > handlers. if you returned SERVER_ERROR it would still work, so long as you > set $r->status :) Oh! I totally missed that you're using Apache::Registry. I'm not sure the best way to do it with that, sorry. -- Michael Stella | Sr. Unix Engineer / Developer | http://www.thismetalsky.org "All I want out of the Universe is 10 minutes with the source code and a quick recompile." - unknown -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: $r->headers_out Location and Set-Cookie
Michael wrote: On Wed, Sep 03, 2003 at 09:42:00, Garrett Goebel said... 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? http://marc.theaimsgroup.com/?l=apache-modperl&m=106260380606735&w=2 thanks, I meant to put that in myself :) Seems to me you'd want to *return* REDIRECT, not set $r->status to REDIRECT. Here's what I do in this case: $r->header_out(Location => $location); return REDIRECT; I don't know if it's 100% correct, but it works quite well for me. actually, the return value is entirely ignored in Registry scripts - that's why we need the $r->status hack, which is not needed (or desired) in handlers. if you returned SERVER_ERROR it would still work, so long as you set $r->status :) however, yes, I prefer your way and return REDIRECT instead of OK - it just seems to make things that much closer to handler behavior, as well as being a bit more intuitive. --Geoff -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
Re: $r->headers_out Location and Set-Cookie
On Wed, Sep 03, 2003 at 09:42:00, Garrett Goebel said... >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? Seems to me you'd want to *return* REDIRECT, not set $r->status to REDIRECT. Here's what I do in this case: $r->header_out(Location => $location); return REDIRECT; I don't know if it's 100% correct, but it works quite well for me. I've also used $r->internal_redirect($location) for some things, but I don't think that's appropriate here. -- Michael Stella | Sr. Unix Engineer / Developer | http://www.thismetalsky.org "To dwell on the destination is to waste the journey" -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
RE: FW: $r->headers_out Location and Set-Cookie
Title: RE: FW: $r->headers_out Location and Set-Cookie Geoffrey Young wrote: > Garrett Goebel wrote: > > [Note: reposting, the original post appears to have dropped > > through the cracks] > > not only did I get two of these already, but I also posted a reply :) My bad. It was an old thread and I didn't scan far enough through the list archives. Problem must be at the company mail server. I've been getting infrequent diagnostic messages from various mailing list daemons. Apologies... -- 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
Re: FW: $r->headers_out Location and Set-Cookie
Garrett Goebel wrote: [Note: reposting, the original post appears to have dropped through the cracks] not only did I get two of these already, but I also posted a reply :) --Geoff -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html
FW: $r->headers_out Location and Set-Cookie
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
Re: $r->headers_out Location and Set-Cookie
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
RE: $r->headers_out Location and Set-Cookie
Title: RE: $r->headers_out Location and Set-Cookie 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
$r->headers_out Location and Set-Cookie
I have the next problem, i am in page A that points to page B, that is a modperl2 handler. This handler makes a job and decides to send a cookie to the browser, and after to redirect to the same page A who is ready to catch the cookie. Then the problem is that if i put the two headers, i don't have the cookie posted, but if i comment the Location header, then i stay at perl handler location, and if i go manually to page A then i see that the cookie is posted. So why these two headers doesn't respect themselves? Resuming $r->headers_out->{'Set-Cookie'} = $cookie; $r->headers_out->{'Location'} = $url; Redirects the page to $url but cookie is not seen by browser $r->headers_out->{'Set-Cookie'} = $cookie; #$r->headers_out->{'Location'} = $url; Location is the perl handler 'localhost/pageB/' (perl handler), if you then go to localhost/pageA (or simply click BACK button) then the browser DO see the cookie! Any idea? - Un nuevo buscador más rápido, eficaz y sencillo http://www.plaf.com Ya.com ADSL Home 24h, Módem + Alta + 1 mes Gratis http://acceso.ya.com/adslhome24h/
Re: Re: $r->headers_out Location and Set-Cookie
Hi, I've seen that the key is the status returned to apache. With Apache::REDIRECT i have the next code works ok $apache->err_headers_out->{'Set-Cookie'} = $value1; $apache->err_headers_out->{'Location'} = $value2; But exactly what's the difference between err_headers_out and headers_out? I understand that the first is related with an error message sended by headers, but i mean, really what does apache make different? I find there is poor docs about that ... maybe i don't know where are the good docs??? - Original Message - Ahh, didn't know that.. Thanks Stas! -Chris - Original Message - From: "Stas Bekman" To: "Chris Faust" Cc: ; Sent: Sunday, August 10, 2003 2:37 PM Subject: Re: $r->headers_out Location and Set-Cookie > Chris Faust wrote: > > I haven't had any problems setting a cookie and redirecting on MP2 by using > > the below > > > > $r->err_headers_out->add('Set-Cookie' => $packed_cookie); > > $r->header_out('Location' => $url); > > $r->status(REDIRECT); > > $r->send_http_header; > > 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. - Un nuevo buscador más rápido, eficaz y sencillo http://www.plaf.com Ya.com ADSL Home 24h, Módem + Alta + 1 mes Gratis http://acceso.ya.com/adslhome24h/
Re: $r->headers_out Location and Set-Cookie
On Saturday, Aug 9, 2003, at 15:26 Europe/London, Nick Tonkin wrote: On Sat, 9 Aug 2003, gerard uolaquetalestem wrote: I have the next problem, i am in page A that points to page B, that is a modperl2 handler. This handler makes a job and decides to send a cookie to the browser, and after to redirect to the same page A who is ready to catch the cookie. Yep. You need $r->err_headers_out->{'Location'} and you could change to $r->err_headers_out->{'Set-Cookie'} too. Even that doesn't work. You need to do a Refresh, because that's the only way the browser will register the cookie - Set-Cookie + Location is not compatible (generally - some browsers will accept the cookie). Matt.
Re: $r->headers_out Location and Set-Cookie
Ahh, didn't know that.. Thanks Stas! -Chris - Original Message - From: "Stas Bekman" <[EMAIL PROTECTED]> To: "Chris Faust" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, August 10, 2003 2:37 PM Subject: Re: $r->headers_out Location and Set-Cookie > Chris Faust wrote: > > I haven't had any problems setting a cookie and redirecting on MP2 by using > > the below > > > > $r->err_headers_out->add('Set-Cookie' => $packed_cookie); > > $r->header_out('Location' => $url); > > $r->status(REDIRECT); > > $r->send_http_header; > > 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. > > __ > Stas BekmanJAm_pH --> Just Another mod_perl Hacker > http://stason.org/ mod_perl Guide ---> http://perl.apache.org > mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com > http://modperlbook.org http://apache.org http://ticketmaster.com >
Re: $r->headers_out Location and Set-Cookie
Stas Bekman wrote: Chris Faust wrote: I haven't had any problems setting a cookie and redirecting on MP2 by using the below $r->err_headers_out->add('Set-Cookie' => $packed_cookie); $r->header_out('Location' => $url); $r->status(REDIRECT); $r->send_http_header; 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. I've added this to the new mp2 cooking chapter: http://perl.apache.org/docs/2.0/user/coding/cooking.html#Sending_Cookies_in_REDIRECT_Response it would be useful to port interesting entries from http://perl.apache.org/docs/1.0/guide/snippets.html and may be add new ones... __ Stas BekmanJAm_pH --> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: $r->headers_out Location and Set-Cookie
Chris Faust wrote: I haven't had any problems setting a cookie and redirecting on MP2 by using the below $r->err_headers_out->add('Set-Cookie' => $packed_cookie); $r->header_out('Location' => $url); $r->status(REDIRECT); $r->send_http_header; 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. __ Stas BekmanJAm_pH --> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: $r->headers_out Location and Set-Cookie
On Sat, 9 Aug 2003, gerard uolaquetalestem wrote: > > I have the next problem, i am in page A that points to page B, that is > a modperl2 handler. > This handler makes a job and decides to send a cookie to the browser, and > after to redirect to the same page A who is ready to catch the cookie. > > Then the problem is that if i put the two headers, i don't have the cookie > posted, but if i comment the Location header, then i stay at perl handler > location, and if i go manually to page A then i see that the cookie is posted. > > So why these two headers doesn't respect themselves? > > Resuming > $r->headers_out->{'Set-Cookie'} = $cookie; > $r->headers_out->{'Location'} = $url; > Redirects the page to $url but cookie is not seen by browser > > $r->headers_out->{'Set-Cookie'} = $cookie; > #$r->headers_out->{'Location'} = $url; > Location is the perl handler 'localhost/pageB/' (perl handler), if you then go > to localhost/pageA (or simply click BACK button) then the browser DO see > the cookie! > > Any idea? Yep. You need $r->err_headers_out->{'Location'} and you could change to $r->err_headers_out->{'Set-Cookie'} too. - nick -- Nick Tonkin {|8^)>
Re: $r->headers_out Location and Set-Cookie
"gerard uolaquetalestem " <[EMAIL PROTECTED]> writes: [...] > But exactly what's the difference between err_headers_out and > headers_out? I understand that the first is related with an error message > sended by headers, but i mean, really what does apache make different? Here's a straightforward explanation of the difference- http://ken.coar.org/burrow/index?month=2003-07#511 -- Joe Schaefer
Re: $r->headers_out Location and Set-Cookie
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. 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. --Geoff
Re: $r->headers_out Location and Set-Cookie
I haven't had any problems setting a cookie and redirecting on MP2 by using the below $r->err_headers_out->add('Set-Cookie' => $packed_cookie); $r->header_out('Location' => $url); $r->status(REDIRECT); $r->send_http_header; -Chris - Original Message - From: "gerard uolaquetalestem " <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, August 09, 2003 10:01 AM Subject: $r->headers_out Location and Set-Cookie I have the next problem, i am in page A that points to page B, that is a modperl2 handler. This handler makes a job and decides to send a cookie to the browser, and after to redirect to the same page A who is ready to catch the cookie. Then the problem is that if i put the two headers, i don't have the cookie posted, but if i comment the Location header, then i stay at perl handler location, and if i go manually to page A then i see that the cookie is posted. So why these two headers doesn't respect themselves? Resuming $r->headers_out->{'Set-Cookie'} = $cookie; $r->headers_out->{'Location'} = $url; Redirects the page to $url but cookie is not seen by browser $r->headers_out->{'Set-Cookie'} = $cookie; #$r->headers_out->{'Location'} = $url; Location is the perl handler 'localhost/pageB/' (perl handler), if you then go to localhost/pageA (or simply click BACK button) then the browser DO see the cookie! Any idea? - Un nuevo buscador mas rapido, eficaz y sencillo http://www.plaf.com Ya.com ADSL Home 24h, Modem + Alta + 1 mes Gratis http://acceso.ya.com/adslhome24h/