X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FCGI.pm;h=004468121354b6c2962eb2efd6d62922ba32d2c2;hb=e2fd5b5f162a33895ad401a8d31fca481c478a8c;hp=af26d08e9c20dd017a708c09a0a14387d4e8be6f;hpb=e7c0c583d6e12e822dd26bf1282eb610c9a59351;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index af26d08..0044681 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -1,11 +1,9 @@ package Catalyst::Engine::CGI; use strict; -use base 'Catalyst::Engine'; +use base 'Catalyst::Engine::CGI::Base'; use CGI; -use URI; -use URI::http; __PACKAGE__->mk_accessors('cgi'); @@ -47,67 +45,28 @@ useful in production applications, but it may be helpful for development. =item $c->cgi -This config parameter contains the C object. +Contains the C object. =back =head1 OVERLOADED METHODS -This class overloads some methods from C. +This class overloads some methods from C. =over 4 -=item $c->finalize_headers +=item $c->prepare_body =cut -sub finalize_headers { +sub prepare_body { my $c = shift; - $c->response->header( Status => $c->response->status ); + # XXX this is undocumented in CGI.pm. If Content-Type is not + # application/x-www-form-urlencoded or multipart/form-data + # CGI.pm will read STDIN into a param, POSTDATA. - print $c->response->headers->as_string("\015\012"); - print "\015\012"; -} - -=item $c->finalize_output - -Prints the response output to STDOUT. - -=cut - -sub finalize_output { - my $c = shift; - print $c->response->output; -} - -=item $c->prepare_connection - -=cut - -sub prepare_connection { - my $c = shift; - $c->req->hostname( $ENV{REMOTE_HOST} ); - $c->req->address( $ENV{REMOTE_ADDR} ); -} - -=item $c->prepare_headers - -=cut - -sub prepare_headers { - my $c = shift; - - while ( my ( $header, $value ) = each %ENV ) { - - next unless $header =~ /^(HTTP|CONTENT)/i; - - ( my $field = $header ) =~ s/^HTTPS?_//; - - $c->req->headers->header( $field => $value ); - } - - $c->req->method( $ENV{REQUEST_METHOD} || 'GET' ); + $c->request->body( $c->cgi->param('POSTDATA') ); } =item $c->prepare_parameters @@ -117,50 +76,32 @@ sub prepare_headers { sub prepare_parameters { my $c = shift; - for my $param ( $c->cgi->param ) { - my @values = $c->cgi->param($param); - $c->req->parameters->{$param} = ( @values > 1 ) ? \@values : $values[0]; - } -} - -=item $c->prepare_path - -=cut - -sub prepare_path { - my $c = shift; + my ( @params ); - my $base; - { - my $scheme = $ENV{HTTPS} ? 'https' : 'http'; - my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME}; - my $port = $ENV{SERVER_PORT} || 80; - my $path = $ENV{SCRIPT_NAME} || '/'; - - $base = URI->new; - $base->scheme($scheme); - $base->host($host); - $base->port($port); - $base->path($path); - - $base = $base->canonical->as_string; + if ( $c->request->method eq 'POST' ) { + for my $param ( $c->cgi->url_param ) { + for my $value ( $c->cgi->url_param($param) ) { + push ( @params, $param, $value ); + } + } } - my $path = $ENV{PATH_INFO} || '/'; - $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; - $path =~ s/^\///; + for my $param ( $c->cgi->param ) { + for my $value ( $c->cgi->param($param) ) { + push ( @params, $param, $value ); + } + } - $c->req->base($base); - $c->req->path($path); + $c->request->param(@params); } =item $c->prepare_request =cut -sub prepare_request { - my $c = shift; - $c->cgi( CGI->new ); +sub prepare_request { + my ( $c, $cgi ) = @_; + $c->cgi( $cgi || CGI->new ); $c->cgi->_reset_globals; } @@ -172,9 +113,9 @@ sub prepare_uploads { my $c = shift; my @uploads; - + for my $param ( $c->cgi->param ) { - + my @values = $c->cgi->param($param); next unless ref( $values[0] ); @@ -189,36 +130,30 @@ sub prepare_uploads { my $disposition = $info->{'Content-Disposition'}; my $filename = ( $disposition =~ / filename="([^;]*)"/ )[0]; - my $upload = { - fh => $fh, + my $upload = Catalyst::Request::Upload->new( filename => $filename, size => $size, tempname => $tempname, type => $type - }; - + ); + push( @uploads, $param, $upload ); } } - - $c->req->_assign_values( $c->req->uploads, \@uploads ); -} - -=item $c->run -=cut - -sub run { shift->handler } + $c->request->upload(@uploads); +} =back =head1 SEE ALSO -L. +L L L. =head1 AUTHOR Sebastian Riedel, C +Christian Hansen, C =head1 COPYRIGHT