You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris D'Annunzio <ch...@lioninc.com> on 2000/04/18 23:14:17 UTC

Passing POST Data to a SubRequest

Is there a way to pass data into a SubRequest using the post method?

I'm sure there's something I'm missing ... here's what I have so far:

Inside the content handler of my priamary request I can create a subrequest using
    my $subr = $r->lookup_uri($uri);

I realize that I can set various headers like the Content-Type and Content-Length using
    $subr->header_in('Content-Length' => 1234);

Then I can run the content handler of the subrequest using
    $subr->run;


Inside the content handler for the subrequest I want to be able to read the data using:
    $r->read($buff, $r->header_in('Content-Length'));

Any ideas on how I would set-up the buffer that $r->read() reads from?

Regards,
Chris D'Annunzio

Re: Passing POST Data to a SubRequest

Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 20 Apr 2000, Chris D'Annunzio wrote:

> 
> > > Is there a way to pass data into a SubRequest using the post method?
> >
> > no, you'll need to use GET and $r->args
> >
> > which can be made transparent with the module below, provided your code
> > can deal with post POST and GET requests.
> 
> That works great if the Content-Type of the POST is
> application/x-www-form-urlencoded.  Is there a way to deal with other
> Content-Types like multipart/form-data?

for something like that, you'd be better off using the $r->pnotes table to
pass a CGI.pm or Apache::Request object to the subrequest.
Apache::RequestNotes on cpan might be useful to you.


Re: Passing POST Data to a SubRequest

Posted by Chris D'Annunzio <ch...@lioninc.com>.
> > Is there a way to pass data into a SubRequest using the post method?
>
> no, you'll need to use GET and $r->args
>
> which can be made transparent with the module below, provided your code
> can deal with post POST and GET requests.

That works great if the Content-Type of the POST is
application/x-www-form-urlencoded.  Is there a way to deal with other
Content-Types like multipart/form-data?

Best Regards,
Chris D'Annunzio


Re: Passing POST Data to a SubRequest

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 18 Apr 2000, Chris D'Annunzio wrote:

> Is there a way to pass data into a SubRequest using the post method?

no, you'll need to use GET and $r->args

which can be made transparent with the module below, provided your code
can deal with post POST and GET requests.

package Apache::POST2GET;

use Apache::Constants qw(M_GET);

sub handler {
    my $r = shift;
    if ($r->method eq 'POST') { 
       my $content = $r->content;
       $r->args($content);
       $r->method('GET');
       $r->method_number(M_GET);
       $r->headers_in->unset('Content-length');
    }
}

__END__

#httpd.conf

PerlInitHandler Apache::POST2GET