Example A-1. Apache/POST2GET.pm
package Apache::POST2GET;
use Apache::Constants qw(M_GET OK DECLINED);
sub handler {
my $r = shift;
return DECLINED unless $r->method eq "POST";
$r->args(scalar $r->content);
$r->method('GET');
$r->method_number(M_GET);
$r->headers_in->unset('Content-length');
return OK;
}
1;
In httpd.conf add:
PerlInitHandler Apache::POST2GET
or even this:
<Limit POST>
PerlInitHandler Apache::POST2GET
</Limit>
to save a few more cycles. This ensures that the handler will be
called only for POST requests.
Be aware that this will work only if the POST ed
data doesn't exceed the maximum allowed size for
GET requests. The default maximum size is 8,190
bytes, but it can be lowered using the
LimitRequestLine configuration directive.
Effectively, this trick turns the POST request
into a GET request internally. Now when a module
such as CGI.pm or
Apache::Request parses the client data, it can do
so more than once, since $r->args
doesn't go away (unless you make it go away by
resetting it).
If you are using Apache::Request, it solves this
problem for you with its instance( ) class method,
which allows Apache::Request to be a singleton.
This means that whenever you call
Apache::Request->instance( ) within a single
request, you always get the same Apache::Request
object back.
| | |
A. mod_perl Recipes | | A.3. Redirecting POST Requests |