How to modify post request content using mod_perl's filter/handler?
I can read request content in PerlResponseHandler but how do I "attach" modified content back into request?
Also, I don't want to do this in PerlResponseHandler as I want requested resource to handle response generation part.
Any help will be appreciated.
Thanks.
if you add use Apache2::RequestIO
and from my ($r) = @_;
you can do a $r->print();
a PerlResponseHandler
can not modify request data, but even if it could what would be the point. Only a PerlInputFilterHandler
can do that as it filters input before it gets to a response.
The only thing after a response handler is the Output Filters, Log Handler, and the Cleanup Handler.
package MyFilter; use strict; use base qw(Apache::Filter); use Apache2::Const qw(OK); sub handler: FilterRequestHandler { my ($f) = @_; while($f->read(my $buf, 1024)) { # do something with $buf $f->print($buf); } return OK; } 1;
Important to know, that you will get data in chunks. When you read you may or may not get the whole posted in a single call.