Sebastian Celis
mod_python at turias.net
Sat Nov 18 10:20:02 EST 2006
Why not create a wrapper to Cookie.add_cookie() that, in addition to writing the cookie, also saves it to a dictionary you create at req.cookies_written? That way, unless you are interfacing with other cookie-writing code, you can always check which cookies you have already placed in the outgoing headers. - Sebastian On 11/18/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote: > > On 18/11/2006, at 4:46 AM, Istvan De wrote: > > > Hi Graham, > > > > On Fri, 2006-11-17 at 20:21 +1100, Graham Dumpleton wrote: > >> On 17/11/2006, at 8:09 PM, Istvan De wrote: > >> > >>> Hi! > >>> > >>> In my code, if I detect that a cookie is not set, I set it using > >>> Cookie.add_cookie(). > >>> > >>> That is all well. However, if I read this cookie from the same > >>> request > >>> at which it was added, it is not available. I guess this is because > >>> the > >>> "cookie add" function puts the cookie into the reponse of the page, > >>> and > >>> the "cookie get" function only looks at the request to see what > >>> cookies > >>> are set. > >>> > >>> What is the solution to my problem? > >> > >> Cookie.get_cookies() reads from req.headers_in. Cookie.add_cookie() > >> writes to req.headers_out. Thus, you can't read back what you only > >> just > >> wrote. > >> > >> Suggest you log using apache.log_error() the values of the input and > >> output headers to see what they are set to. > >> > >> Note that Cookie.add_cookie() must be called prior to the first time > >> that > >> any actual content is written back as the response. > > > > Yes, these are all clear to me. But what do you advise as the solution > > to the problem? I need to read some cookies just created. Or maybe > > re-load the page with a meta tag after creating the cookies? But this > > would be sort of a hack. > > Please keep discussion on the mailing list. > > It is unclear why you would want to do it in the first place which > possibly > suggests that whatever you are doing you are going about it all in the > wrong way. Can you explain what problem it is you are really trying to > solve. > > Anyway, req.headers_in should be writable and so you could always > create the 'cookie' header and resave it. That can be a bit tricky > though > if you are getting sent multiple cookies as you potentially have to > merge > it back in with those other cookies. > > Graham > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|