walinsky has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

in a given situation we get xml data POSTed to our server, much alike RPC calls (actually they're a number of http (webdav) requests).

A (mod_perl) Fixuphandler traps these requests, parses the xml, and (should) from there on issue all requests to our server.

It seemed quite logical to (dynamically) create a subrequest for each given request. We would dynamically add a input filter to each subrequest, create a bucket brigade there, and fill the bb with the desired data; set the correct request headers, and run the sub-request.

(Part of) the code in the input filter that should do the trick is:

$bb = APR::Brigade->new($c->pool, $c->bucket_alloc); my $ba = $bb->bucket_alloc(); my $nb = APR::Bucket->new($ba, $data); $bb->insert_tail($nb); my $b = APR::Bucket::eos_create($ba); $bb->insert_tail($b); $r->headers_in->{'Content-Length'} = length ($data); $f->fflush($bb);

For some reason, the sub-request never picks up the bucket brigade. Is there something I've overseen, or am I just trying to do the plain impossible ?

rgrds,

walinsky

  • Comment on mod_perl - using input filters and bucket brigades to pass data to subrequests
  • Download Code

Replies are listed 'Best First'.
Re: mod_perl - using input filters and bucket brigades to pass data to subrequests
by perrin (Chancellor) on Mar 10, 2008 at 17:04 UTC
    No offense, but you're making this way more difficult than it needs to be.

    Don't make subrequests unless you have a real reason for it, like needing to run some special auth handler that can't be called directly from perl. They have overhead and complicate things. You can easily set a specific handler or directly call some perl code without any need for subrequests. It's simpler and faster.

    The way to pass data between phases or requests is $r->pnotes(). You just put the data there and then grab it in the next phase or subrequest. If you are in a subrequest, you have to ask for the parent request's record and look there for it. I think that's just $r->parent() but that's off the top of my head and could be wrong.

      The main reason for making subrequests is that we're getting a bunch of WEBDAV requests bundled in the POSTed request. We don't want to handle those in perl, as mod_dav was built to do it. We are already using the $r->pnotes for passing the data from the handler to the input filter.

      An other option would be using LWP - but that seems quite stupid, as we would loose the whole request environment.

      A third option would be writing xs code for gluing perl to mod_dav. If one has that code handy already, I'd be more than interested in trying that way

        Ok, you could use subrequests for that. I'd still check out CPAN's DAV modules though. If you think subrequests to mod_dav are the way to go, bring your question about filters over to the mod_perl mailing list.