[mod_python] I need to create a Zip file on the fly and write itto the stream without any temp files or in memory file creation?

Graham Dumpleton grahamd at dscpl.com.au
Mon Mar 6 22:58:12 EST 2006


jarrod roberson wrote ..
> On 3/6/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> >
> >
> > FWIW, just because mod_dav is taking over the bulk of the response
> > handling, can't see why specific URLs couldn't be intercepted and
> > made to fire off his existing Java implementation. He hasn't explained
> > the relationship between URL namespace managed by mod_dav and
> > the Java stuff to be able to explore that avenue though.
> >
> > Graham
> >
> 
> it gets kind of complicated, but the folders we are trying to stream are
> in
> the middle of a directory structure that is handled by mod_dav Directory
> directive, it seems that mod_dav doesn't play nice with mod_proxy or
> mod_rewrite in our case. I am _not_ an Apache 2 expert by any means, but
> they guys that are, asked me if I could get this done "inline" so as not
> have to deal with the complications that Apache is causing.

Mod_dav registers three handler hooks:

    ap_hook_handler(dav_handler, NULL, NULL, APR_HOOK_MIDDLE);
    ap_hook_post_config(dav_init_handler, NULL, NULL, APR_HOOK_MIDDLE);
    ap_hook_fixups(dav_fixups, NULL, NULL, APR_HOOK_MIDDLE);

The response handler will only be run if req.handler is set to "dav-handler".
It will be set to this by dav_fixups().

Mod_python also runs as a middle hook in fixup phase, but if you can get
the ordering correct you could register a mod_python fixup handler which
override the req.handler attribute when request is against a specific URL
so that it is handled by something else.

Unfortunately, 3.2.8 and earlier versions of mod_python probably aren't
going to help. If you were using mod_python from subversion repostory
it probably would though as req.handler is writable in that version where
as it wasn't in earlier versions.

Anyway, as a test to sort out ordering, register a fixup handler:

  PythonFixupHandler _handler_check

  from mod_python import apache

  def fixuphandler(req):
    req.log_error("handler = %s" % req.handler)
    return apache.OK

If the error log shows req.handler already set to "dav-handler" you are in
business, if not, play with order to PythonFixupHandler relative to directives
that enable mod_dav on the directory so that mod_python fixup handler
is run second.

If you then mod_python from subversion repository, you could do:

  from mod_python import apache

  def fixuphandler(req):
    if req.uri = "/some/path":
      req.handler = "name_of_java_handler_module"
    return apache.OK

where req.handler is the handler name for the Java module which knows
how to performing ziping of stuff identified by req.filename. If necessary,
you could modify req.uri or req.filename. See:

  https://issues.apache.org/jira/browse/MODPYTHON-125

Another alternative is to use:

  from mod_python import apache

  def fixuphandler(req):
    if req.uri = "/some/path":
      req.internal_redirect("/some/other/path")
    return apache.DONE

The "/some/other/path" would be what identifies the Java stuff.

Finally, could also consider triggering mod_proxy. See:

  https://issues.apache.org/jira/browse/MODPYTHON-141

As I pointed out though, these tricks require subversion version of
mod_python.

Even if you do handle it inline, you still need to intercept it like above
to trigger a mod_python handler to do it, or intercept using Location
directive.

Graham


More information about the Mod_python mailing list