[albatross-users] Changing the status code

Dave Cole djc at object-craft.com.au
Fri Nov 29 20:51:17 EST 2002


>>>>> "Michael" == Michael C Neel <neel at mediapulse.com> writes:

Michael> Thanks for the answer.

I suppose we should make the proposed changes for the next release
then.

Michael> I should be able to write a small class to wrap the current
Michael> mod_python version of Request to do this.  In the meantime I
Michael> worked arounf it using a meta tag, but this open up other
Michael> options (us as setting a cookie in an access denied page -
Michael> why, not sure why you would want to, but it's always good to
Michael> know you can!).

Michael> Do you do anything for US thanksgiving (wouldn't make much
Michael> since, lol)?

Not yet.  It wouldn't surprise me if we started to do something within
the next decade though.  We have kids occasionally walking around on
Halloween trying to sting us for lollies.  They tend not to be very
successful :-)

Michael> Ah well, either way, have a happy thanksgiving!

Thanks.  Make sure you eat yourself into unconsciousness!

- Dave

>> -----Original Message----- From: djc at ferret.object-craft.com.au
>> [mailto:djc at ferret.object- craft.com.au] On Behalf Of Dave Cole
>> Sent: Wednesday, November 27, 2002 6:10 PM To: Michael C. Neel Cc:
>> albatross-users at object-craft.com.au Subject: Re: [albatross-users]
>> Changing the status code
>> 
>> 
>> > I'm having trouble setting the status of a page though albatross
>> > using mod_python.
>> 
>> Albatross does not really help you here.  At the moment all
>> non-exception processing returns status 200.  The culprit is the
>> run() method in the Application class.
>> 
>> The status() method on the Request class translates an HTTP status
>> code to something that can be returned as a status code to the
>> execution framework.  That seems a little obscure...  Consider the
>> way that a mod_python application works:
>> 
>> from albatross.apacheapp import Request
>> :
>> :
>> app = App()
>> 
>> def handler(req): return app.run(Request(req))
>> 
>> mod_python expects the return value for the handler() function to
>> be zero if everything is OK.  The status() method in
>> apacheapp.Request simply translates the 200 from the
>> Application.run() method to zero.
>> 
>> > I've snipped out extra lines here, but the idea is to set a
>> cookie > with the redirect.  The ctx.request.redirect function
>> ignores any > custom headers, so I had to roll my own here.
>> 
>> Something which we could certainly improve is the interface for
>> manipulating headers.
>> 
>> > and then in the StdForm class:
>> >
>> > def page_process(self, ctx):
>> >
>> > ctx.request.status(apache.HTTP_MOVED_PERMANENTLY)
>> 
>> The status() method does not change the status which is returned by
>> the handler function.  Currently we do not have a way to do this.
>> 
>> If we do not get any objections, I suggest that we make the
>> following changes:
>> 
>> In all Request classes:
>> 
>> def Request: def __init__(self, req): self.__status = 200
>> 
>> def set_status(self, status): self.__status = status
>> 
>> def status(self): # For mod_python...  if self.__status == 200:
>> return 0 return self.__status
>> 
>> Then in the Application.run() method:
>> 
>> def run(self, req):
>> :
>> :
>> return req.status()
>> 
>> This would allow you to simply change the returned status by doing
>> a small variation of your code above:
>> 
>> def page_process(self, ctx):
>> ctx.request.set_status(apache.HTTP_MOVED_PERMANENTLY)
>> 
>> - Dave
>> 
>> -- http://www.object-craft.com.au


Michael> _______________________________________________
Michael> Albatross-users mailing list
Michael> Albatross-users at object-craft.com.au
Michael> https://www.object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list