[albatross-users] Changing the status code

Michael C. Neel neel at mediapulse.com
Thu Nov 28 10:35:37 EST 2002


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

Do you do anything for US thanksgiving (wouldn't make much since, lol)?
Ah well, either way, have a happy thanksgiving!

Mike

> -----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





More information about the Albatross-users mailing list