Apache-ASP
view release on metacpan or search on metacpan
lib/Apache/ASP/Request.pm view on Meta::CPAN
eval "use CGI;";
} else {
# default leaves no temp files for prying eyes
eval "use CGI qw(-private_tempfiles);";
}
if($@) {
$self->{asp}->Error("can't use file upload without CGI.pm: $@");
goto ASP_REQUEST_POST_READ_DONE;
}
# new behavior for file uploads when FileUploadMax is exceeded,
# before it used to error abruptly, now it will simply skip the file
# upload data
local $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS;
if($asp->{file_upload_max} = &config($asp, 'FileUploadMax')) {
if($self->{TotalBytes} > $asp->{file_upload_max} ) {
$CGI::DISABLE_UPLOADS = 1;
}
}
$asp->{dbg} && $asp->Debug("using CGI.pm version ".
(eval { CGI->VERSION } || $CGI::VERSION).
" for file upload support"
);
my %form;
my $q = $self->{cgi} = new CGI;
$asp->Debug($q->param);
for(my @names = $q->param) {
my @params = $q->param($_);
$form{$_} = @params > 1 ? [ @params ] : $params[0];
if(ref($form{$_}) eq 'Fh') {
my $fh = $form{$_};
binmode $fh if $asp->{win32};
$upload{$_} = $q->uploadInfo($fh);
if($asp->{file_upload_temp}) {
$upload{$_}{TempFile} = $q->tmpFileName($fh);
$upload{$_}{TempFile} =~ s|^/+|/|;
}
$upload{$_}{BrowserFile} = "$fh";
$upload{$_}{FileHandle} = $fh;
$upload{$_}{ContentType} = $upload{$_}{'Content-Type'};
# tie the file upload reference to a collection... %upload
# may be many file uploads note.
$upload{$_} = bless $upload{$_}, 'Apache::ASP::Collection';
$asp->{dbg} && $asp->Debug("file upload field processed for \$Request->{FileUpload}{$_}", $upload{$_});
}
}
$form = \%form;
} else {
$self->{asp}->Debug("FileUploadProcess is disabled, file upload data in \$Request->BinaryRead");
}
} else {
# Only tie to STDIN if we have cached contents
# don't untie *STDIN until DESTROY, so filtered handlers
# have an opportunity to use any cached contents that may exist
if(my $len = $self->{TotalBytes}) {
$self->{content} = $self->BinaryRead($len) || '';
tie(*STDIN, 'Apache::ASP::Request', $self);
#AJAX POSTs are ``application/x-www-form-urlencoded; charset=UTF-8'' in Firefox3+
#by Richard Walsh Nov 25, 2008 (found in nabble)
if($headers_in->get('Content-Type') =~ m|^application/x-www-form-urlencoded|) {
$form = &ParseParams($self, \$self->{content});
} else {
$form = {};
}
}
}
}
ASP_REQUEST_POST_READ_DONE:
$self->{'Form'} = bless $form, 'Apache::ASP::Collection';
$self->{'FileUpload'} = bless \%upload, 'Apache::ASP::Collection';
my $query = $r->args();
my $parsed_query = $query ? &ParseParams($self, \$query) : {};
$self->{'QueryString'} = bless $parsed_query, 'Apache::ASP::Collection';
if(&config($asp, 'RequestParams')) {
$self->{'Params'} = bless { %$parsed_query, %$form }, 'Apache::ASP::Collection';
}
# do cookies now
my %cookies;
if(my $cookie = $headers_in->get('Cookie')) {
my @parts = split(/;\s*/, ($cookie || ''));
for(@parts) {
my($name, $value) = split(/\=/, $_, 2);
$name = &Unescape($self, $name);
next if ($name eq $Apache::ASP::SessionCookieName);
next if $cookies{$name}; # skip dup's
$cookies{$name} = ($value =~ /\=/) ?
&ParseParams($self, $value) : &Unescape($self, $value);
}
}
$self->{Cookies} = bless \%cookies, 'Apache::ASP::Collection';
$self;
}
sub DESTROY {
my $self = shift;
if($self->{cgi}) {
# make sure CGI file handles are freed
$self->{cgi}->DESTROY();
$self->{cgi} = undef;
}
for(keys %{$self->{FileUpload}}) {
my $upload = $self->{FileUpload}{$_};
$self->{Form}{$_} = undef;
if($upload->{FileHandle}) {
close $upload->{FileHandle};
# $self->{asp}->Debug("closing fh $upload->{FileHandle}");
}
$self->{FileUpload}{$_} = undef;
}
( run in 2.366 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )