[mod_python] Cookies and redirect...

Gregory (Grisha) Trubetskoy grisha at modpython.org
Thu Aug 14 10:17:14 EST 2003


This is a feature of Apache. When it sees an error response (all 204 (no
content), 3xx (redirect), 4xx (client error) and 5xx (server error)),
which includes HTTP_MOVED_TEMPORARILY (even though it's not an error
technically), it sends out only req.err_headers_out. It does make a
special provision for the Location header and copy it into err_headers_out
if it's not already there, which is why it makes it through.

You can send both headers by either:

   req.err_headers_out.add('Set-Cookie', morsel.OutputString())
   req.err_headers_out.add('Location:', location)
   return apache.HTTP_MOVED_TEMPORARILY

or

   req.headers_out.add('Set-Cookie', morsel.OutputString())
   req.status = apache.HTTP_MOVED_TEMPORARILY
   return apache.OK

Grisha


On Thu, 14 Aug 2003, David Fraser wrote:

> Hi
>
> I came across the following problem and wondered if there was a workaround.
> Basically I want to set a cookie in a certain directory, and at the same
> time issue a Redirect to another place.
> So I wanted to do:
>   req.headers_out.add('Set-Cookie', morsel.OutputString())
>   req.headers_out.add('Location:', location)
>   return apache.HTTP_MOVED_TEMPORARILY
>
> However, I found that as soon as I return the HTTP_MOVED_TEMPORARILY,
> the Set-Cookie string seems to be removed from the headers going to the
> client (this was tested by using the livehttpheaders extension to Firebird).
> I couldn't work out where in the code that was happening but suspect
> that it is standard Apache behaviour.
> Is this because I'm not supposed to be allowed to do this, or is it odd?
>
> (I have a workaround of having a page with a meta http-equiv="refresh",
> but wondered if there is a way to get it working as would like...)
>
> Thanks
> David
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list