|
Byron Ellacott
bje at apnic.net
Fri Feb 6 09:17:37 EST 2004
On Fri, 2004-02-06 at 04:15, Bud P. Bruegger wrote:
> Is it possible with modpython (apache) to set a cookie at the authentiction
> stage while a later stage interfaces to some kind of "application servers"
> (j2ee, cgi, fcgi, modpython PythonHandler, etc.) that create the actual
> response?
The req.headers_out member is a table object. If later phases correctly
use .add() rather than directly assigning to
req.headers_out['Set-Cookie'], then the values you add in earlier phases
should survive.
> server. The manual states that "You can dynamically assign attributes to
> [the request object] as a way to communicate between handlers". Is this
> the mechanism that I could use to communicate the cookie data? If so, does
> anyone have an example for such communications? And also, what stage would
> I use to actually set the cookie (is the cleanup handler a good choice?).
--snip--
def authenhandler(req):
req.is_bje = req.user == 'bje'
return apache.OK
def handler(req):
req.send_http_header()
req.write('<html><head></head><body>\r\n')
if req.is_bje:
req.write('You are bje!\r\n')
else:
req.write('You are NOT bje!\r\n')
req.write('</body></html>\r\n')
return apache.OK
--snip--
Just like that. It is important to note that the request object is
specific to the interpreter it is running in. Thus, if you have a
directive that changes the interpreter between phases, you will get a
new request object built, and your attribute(s) will vanish!
In other words, if you have a <Files> section with a PythonInterpreter
statement in it, you most likely cannot rely on attributes from earlier
phases being available.
--
bje
|