[mod_python] cookies and redirects

John Aherne johna at johnaherne.co.uk
Fri Nov 5 02:18:05 EST 2004


John Aherne wrote:

> Byron Ellacott wrote:
>
>>     req.err_headers_out.add('Set-Cookie', check)
>
> It looks like redirect is not a good option if you want to use 
> cookies. I'll have to take a look at doing it some other way.


External redirect, particularly a 307 redirect for HTTP/1.1 clients, is 
generally the best way to handle changing a location in response to a 
request.  Using a 307 means the client's back button works right, reload 
works right, and the URL location bar works right.

If you're doing a redirect, and you want to keep your cookies, you can 
always use the line I showed above to save them into 
req.err_headers_out, which should solve the problem.

-- 

Byron

Thanks for the extra information.

I tried your suggestion and it does the trick.

I haven't worked out how to do a 307 yet, but hopefully I'll find this 
out over the next few days.

I may be naive or missing the point but:--

I have a script in PHP that I run against the same process. When I do a 
redirect in PHP it has no problems doing the redirect and saving the 
cookie. I assume it must by default put the cookie into the error 
handler to apache. I assume it must think this ought to be the default 
behaviour required.

Naturally, since your post I have now found endless discussion on this 
very subject in the mail archives. God knows how I missed these when 
trawling through them before.

John Aherne


More information about the Mod_python mailing list