perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jordan Michaels <>
Subject Adding Post Data to a SubRequest
Date Thu, 15 Dec 2011 00:03:18 GMT
I've been working to find a solution to adding Post data to a sub 
request for a few days now (since last week when I posted about 
retrieving the POST data in the first place).

Adding the POST data to the $subr object using write doesn't work, 
because it tries to add it to the output response and not the input request.

I then found a message on google that indicated that you could modify 
the incoming request POST data via a filter, so I've written something 
similar to the following:

use Apache2::SubRequest  ();
use Apache2::ServerUtil  ();
use Apache2::RequestUtil ();
use Apache2::RequestRec  ();
use Apache2::RequestIO   ();
use Apache2::Filter      ();
use Apache2::Log         ();
use APR::Table           ();
use APR::Brigade         ();
use APR::Bucket          ();

sub handler {
	my $r                   = shift;
	our @ProxyInputContent  = ();

	sub proxy_input_filter {
		my ( $f, $bb ) = @_;
		my $ba = $bb->bucket_alloc();
		my $newBucket = '';
		# remove the existing buckets
		# create buckets using the orig request POST data
		foreach ( @ProxyInputContent ) {
			# the current array element will be represented as $_
			# create a new bucket
			$newBucket = APR::Bucket->new($ba, $_);
			# put the new bucket in the subr brigade
		# the subrequest should now contain the post data
		return Apache2::Const::OK;

	# handle POST requests
	if ( $r->method() eq "POST" ) {
		# set the subrequest method to also be a post
		# create a post data buffer
		my $PostBuffer = '';
		# loop over each line of data
		while($r->read($PostBuffer, 1024)) {
			# add the content to the ProxyInputContent Array
			push(@ProxyInputContent, $PostBuffer);
		# make the subrequest go through the input filter so we can add the 
post data to it.
		$subr->add_input_filter( \&proxy_input_filter );

	# perform the proxy request

However, this doesn't work. I still don't see the POST data on the 
Tomcat side.

And, being the noob I am, I haven't yet figured out how to log the data 
from the filter to I can make sure I'm doing it right.

So, my questions are simple:

1) Is there an ideal way to add POST data to a subrequest that I'm 
missing here?

2) Is it possible to log data from a filter so I can debug it?

Thank you *so much* for your help and patience with this. I truly 
appreciate your time.

Warm Regards,
Jordan Michaels

View raw message