[mod_python] Apache directory listing

Graham Dumpleton graham.dumpleton at gmail.com
Tue May 29 18:59:00 EDT 2007


On 30/05/07, Aaron Gallagher <habnabit at gmail.com> wrote:
> Okay, I had limited success with mod_autoindex, but unfortunately it
> seems to be impossible to have Apache autoindex the directory.

I'll have a got at doing what I think you are trying to do later. As I
understand it you want directory index if request against directory,
otherwise SetHandler (or equivalent) should apply. Yes/No?

> Writing my own indexer was pretty simple and it's working well.
>
> Now, though, I'm trying to figure out how to catch errors like 401
> and 403 errors and handle them within my fixuphandler. Is this
> possible? My fixuphandler is currently using the internal_redirect
> function to use a custom 404 page, but I'd like to potentially catch
> all of my errors without using the internal_redirect function.
>
> My authenhandler returns 401 or 403 if there's a bad username or
> password, but it seems that it doesn't go to my fixuphandler but
> apache generates the error pages on its own. It seems like whenever I
> return an error code, apache generates an error page.
>
> So, I guess my question is how I should catch every error to make
> custom error pages?

Use the Apache ErrorDocument directive to specify an internal URL for
the handler which generates the error page. When you return an error
number as status, Apache will invoke the handler associated with the
ErrorDocument for you without you need to do the redirect. If you want
to pass information about the error to the error handler, store it in
req.notes['error-notes']. That value will then be available in
req.subprocess_env of error handler under ERROR_NOTE or
REDIRECT_ERROR_NOTES (cant remember which).

Graham

> On May 28, 2007, at 3:11 PM, Graham Dumpleton wrote:
>
> > BTW, SetHandler is only processed in typehandler phase. Thus if you
> > want to override that, you must be doing it in the fixuphandler phase.
> >
> > Also note that allowing automatic directory listings in mod_python can
> > cause issues if there are subdirectories which are also managed in
> > some way by mod_python. Can't remember whether there is an issue
> > logged about it or whether I ranted about it on one of the mailing
> > lists somewhere.
> >
> > Graham
> >
> > On 29/05/07, Graham Dumpleton <graham.dumpleton at gmail.com> wrote:
> >> If a phase earlier than response handler phase is providing the
> >> complete response, it should return apache.DONE and not apache.OK.
> >> This will stop later phases running.
> >>
> >> Graham
> >>
> >> On 28/05/07, Aaron Gallagher <habnabit at gmail.com> wrote:
> >> > I've just moved a lot of my code (including the code that checks to
> >> > see if a directory should have its contents listed) from a
> >> > PythonHandler into a PythonHeaderParserHandler, because after
> >> looking
> >> > at the response loop, I determined that PythonFixupHandler was
> >> > happening too late in the process.
> >> >
> >> > It's created some interesting new problems -- my calls to
> >> > req.internal_redirect aren't working, as the code was set up
> >> like this:
> >> > req.internal_redirect(...)
> >> > return apache.OK
> >> > I guess this isn't stopping the request, like it used to do. How
> >> > should I change my code to allow internal redirects?
> >> >
> >> > Also, all of your suggestions just act the same way as if I had
> >> just
> >> > done return apache.OK.
> >> >
> >> >
> >> > On May 28, 2007, at 4:22 AM, Graham Dumpleton wrote:
> >> >
> >> > > On 28/05/07, Aaron Gallagher <habnabit at gmail.com> wrote:
> >> > >> Okay, I'll try that.
> >> > >>
> >> > >> But, what exactly is the purpose of a PythonFixupHandler? The
> >> > >> documentation doesn't have much to say, but I assume it's for
> >> doing
> >> > >> URL rewriting and redirection.
> >> > >
> >> > > Potentially. It is one of a number of phases and is a sort of
> >> catch
> >> > > all or last chance phase before actual response handler is
> >> executed.
> >> > > For a very technical description of the whole Apache request-
> >> response
> >> > > loop see:
> >> > >
> >> > >  http://www.fmc-modeling.org/projects/apache/html/
> >> > > 4_4Request_Response_Loop.html
> >> > >
> >> > > If you really want to understand how Apache works, that whole
> >> document
> >> > > is quite a good read, albeit probably more in depth than most
> >> people
> >> > > would care for.
> >> > >
> >> > > Graham
> >> > >
> >> > >> On May 28, 2007, at 3:44 AM, Graham Dumpleton wrote:
> >> > >>
> >> > >> > Arrgghh, mistook mime type for handler.
> >> > >> >
> >> > >> > Trying again, although not sure this will work, but might
> >> be able
> >> > >> > to say:
> >> > >> >
> >> > >> >  req.handler = "httpd/unix-directory"
> >> > >> >  return apache.DECLINED
> >> > >> >
> >> > >> > The reason this might not work is that mod_python registers
> >> > >> itself as
> >> > >> > a middle handler as does the autoindex module. Because the
> >> > >> autoindex
> >> > >> > module is inbuilt, it probably gets processed prior to
> >> mod_python
> >> > >> > handler so too late to do the above.
> >> > >> >
> >> > >> > Thus, your only choice would be to provide a fixuphandler
> >> which
> >> > >> undoes
> >> > >> > the SetHandler just for the request against the directory and
> >> > >> triggers
> >> > >> > autoindex instead. Ie.,
> >> > >> >
> >> > >> >  def fixuphandler(req):
> >> > >> >    if req.content_type = "httpd/x-directory":
> >> > >> >      req.handler = "httpd/unix-directory"
> >> > >> >    return apache.OK
> >> > >> >
> >> > >> > Enable this using appropriate PythonFixupHandler directive.
> >> > >> >
> >> > >> > Graham
> >> > >> >
> >> > >> > On 28/05/07, Aaron Gallagher <habnabit at gmail.com> wrote:
> >> > >> >> I get a 404 Not Found error.
> >> > >> >>
> >> > >> >> On May 28, 2007, at 3:22 AM, Graham Dumpleton wrote:
> >> > >> >>
> >> > >> >> > What happens if you return apache.DECLINED.
> >> > >> >> >
> >> > >> >> > Graham
> >> > >> >> >
> >> > >> >> > On 28/05/07, Aaron Gallagher <habnabit at gmail.com> wrote:
> >> > >> >> >>
> >> > >> >> >> Is there a way to tell Apache to give a directory
> >> listing? I'm
> >> > >> >> using
> >> > >> >> >> SetHandler on a directory, and in some cases, I don't need
> >> > >> to do
> >> > >> >> >> any special
> >> > >> >> >> handling, so I'd like Apache to just list the contents
> >> of the
> >> > >> >> >> directory so
> >> > >> >> >> that I don't have to write my own way of doing it.
> >> > >> >> >>
> >> > >> >> >> Just returning apache.OK has Apache send a document of
> >> MIME
> >> > >> time
> >> > >> >> >> httpd/x-directory with content length 0.
> >> > >> >> >>
> >> > >> >> >> Aaron Gallagher
> >> > >> >> >> <habnabit at gmail.com>
> >> > >> >> >>
> >> > >> >> >>
> >> > >> >> >> _______________________________________________
> >> > >> >> >> Mod_python mailing list
> >> > >> >> >> Mod_python at modpython.org
> >> > >> >> >> http://mailman.modpython.org/mailman/listinfo/mod_python
> >> > >> >> >>
> >> > >> >> >>
> >> > >> >>
> >> > >> >> Aaron Gallagher
> >> > >> >> <habnabit at gmail.com>
> >> > >> >>
> >> > >> >>
> >> > >> >>
> >> > >>
> >> > >> Aaron Gallagher
> >> > >> <habnabit at gmail.com>
> >> > >>
> >> > >>
> >> > >>
> >> >
> >> > Aaron Gallagher
> >> > <habnabit at gmail.com>
> >> >
> >> >
> >> > _______________________________________________
> >> > Mod_python mailing list
> >> > Mod_python at modpython.org
> >> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >> >
> >>
>
> Aaron Gallagher
> <habnabit at gmail.com>
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list