Apache-RequestNotes
view release on metacpan or search on metacpan
RequestNotes.pm view on Meta::CPAN
package Apache::RequestNotes;
#---------------------------------------------------------------------
#
# usage: PerlInitHandler Apache::RequestNotes
# PerlSetVar MaxPostSize 1024 optional size in bytes
# allowed to be POSTed
#
# PerlSetVar DisableUploads On forbid file uploads
#
#---------------------------------------------------------------------
use 5.004;
use mod_perl 1.21;
use Apache::Constants qw( OK );
use Apache::Cookie;
use Apache::Log;
use Apache::Request;
use strict;
$Apache::RequestNotes::VERSION = '0.06';
# set debug level
# 0 - messages at info or debug log levels
# 1 - verbose output at info or debug log levels
$Apache::RequestNotes::DEBUG = 0;
sub handler {
#---------------------------------------------------------------------
# initialize request object and variables
#---------------------------------------------------------------------
my $r = shift;
my $log = $r->server->log;
my $maxsize = $r->dir_config('MaxPostSize') || 1024;
my $uploads = $r->dir_config('DisableUploads') =~ m/Off/i ? 0 : 1;
my %cookies = (); # hash for cookie names and values
$Apache::RequestNotes::err = undef;
#---------------------------------------------------------------------
# do some preliminary stuff...
#---------------------------------------------------------------------
$log->info("Using Apache::RequestNotes");
#---------------------------------------------------------------------
# grab the cookies
#---------------------------------------------------------------------
my %cookiejar = Apache::Cookie->new($r)->parse;
foreach (sort keys %cookiejar) {
my $cookie = $cookiejar{$_};
$cookies{$cookie->name} = $cookie->value;
$log->info("\tcookie: name = ", $cookie->name,
", value = ", $cookie->value) if $Apache::RequestNotes::DEBUG;
}
#---------------------------------------------------------------------
# parse the form data
#---------------------------------------------------------------------
# this routine works for either a get or post request
my $apr = Apache::Request->instance($r, POST_MAX => $maxsize,
DISABLE_UPLOADS => $uploads);
# I assume that Apache::RequestNotes is going to do the job of
# of calling Apache::Request->new(). Hopefully, this is ok...
my $status = $apr->parse;
if ($status) {
# I don't know what to do here, but rather than return
# SERVER_ERROR, do something that says there was a parse failure.
# GET data is still available, but POST looks hosed...
# problems with uploads are caught here as well.
$Apache::RequestNotes::err = $status;
$log->error("Apache::RequestNotes encountered a parsing error!");
$log->info("Exiting Apache::RequestNotes");
return OK;
}
my $input = $apr->parms; # this is a hashref tied to Apache::Table
if ($Apache::RequestNotes::DEBUG) {
$input->do(sub {
my ($key, $value) = @_;
$log->info("\tquery string: name = $key, value = $value");
1;
});
}
#---------------------------------------------------------------------
# create an array of all Apache::Upload objects
#---------------------------------------------------------------------
my @uploads = $apr->upload; # all the Apache::Upload objects
foreach my $upload (@uploads) {
$log->info("\tupload: size = ", $upload->size,
", type = ", $upload->type) if $Apache::RequestNotes::DEBUG;
}
#---------------------------------------------------------------------
# put the form and cookie data in a pnote for access by other handlers
#---------------------------------------------------------------------
( run in 0.590 second using v1.01-cache-2.11-cpan-2398b32b56e )