X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP.pm;h=b708a7ff0837a722401afeac5bb78acfcc5d3d19;hb=5bf293276098f2b467162c75182eb3bc3f7b0119;hp=861ec5a187e02a9258567ff712b8252f411330f8;hpb=66d9e175a28989d4454714edf2cc2dab5ad64d96;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/HTTP.pm b/lib/Catalyst/Engine/HTTP.pm index 861ec5a..b708a7f 100644 --- a/lib/Catalyst/Engine/HTTP.pm +++ b/lib/Catalyst/Engine/HTTP.pm @@ -1,233 +1,23 @@ -package Catalyst::Engine::HTTP; - +package # Hide from PAUSE + Catalyst::Engine::HTTP; use strict; -use base 'Catalyst::Engine'; - -use CGI::Simple::Cookie; -use Class::Struct (); -use HTTP::Headers::Util 'split_header_words'; -use HTTP::Request; -use HTTP::Response; -use IO::File; -use URI; - -__PACKAGE__->mk_accessors(qw/http/); - -Class::Struct::struct 'Catalyst::Engine::HTTP::LWP' => { - request => 'HTTP::Request', - response => 'HTTP::Response', - hostname => '$', - address => '$' -}; - -=head1 NAME - -Catalyst::Engine::HTTP - Catalyst HTTP Engine - -=head1 SYNOPSIS - -L. - -=head1 DESCRIPTION - -This Catalyst engine is meant to be subclassed. - -=head1 OVERLOADED METHODS - -This class overloads some methods from C. - -=over 4 - -=item $c->finalize_headers - -=cut - -sub finalize_headers { - my $c = shift; - - my $status = $c->response->status || 200; - my $headers = $c->response->headers; - my $response = HTTP::Response->new( $status, undef, $headers ); - - while ( my ( $name, $cookie ) = each %{ $c->response->cookies } ) { - my $cookie = CGI::Simple::Cookie->new( - -name => $name, - -value => $cookie->{value}, - -expires => $cookie->{expires}, - -domain => $cookie->{domain}, - -path => $cookie->{path}, - -secure => $cookie->{secure} || 0 - ); - - $response->header( 'Set-Cookie' => $cookie->as_string ); - } - - $c->http->response($response); -} - -=item $c->finalize_output - -=cut - -sub finalize_output { - my $c = shift; - $c->http->response->content_ref( \$c->response->{output} ); -} - -=item $c->prepare_connection - -=cut - -sub prepare_connection { - my $c = shift; - $c->req->hostname( $c->http->hostname ); - $c->req->address( $c->http->address ); -} - -=item $c->prepare_cookies - -=cut - -sub prepare_cookies { - my $c = shift; - - if ( my $header = $c->http->request->header('Cookie') ) { - $c->req->cookies( { CGI::Simple::Cookie->parse($header) } ); - } -} - -=item $c->prepare_headers - -=cut +use warnings; -sub prepare_headers { - my $c = shift; - $c->req->method( $c->http->request->method ); - $c->req->headers( $c->http->request->headers ); -} - -=item $c->prepare_parameters - -=cut - -sub prepare_parameters { - my $c = shift; - - my @params = (); - my $request = $c->http->request; - - push( @params, $request->uri->query_form ); - - if ( $request->content_type eq 'application/x-www-form-urlencoded' ) { - my $uri = URI->new('http:'); - $uri->query( $request->content ); - push( @params, $uri->query_form ); - } - - if ( $request->content_type eq 'multipart/form-data' ) { - - for my $part ( $request->parts ) { - - my $disposition = $part->header('Content-Disposition'); - my %parameters = @{ ( split_header_words($disposition) )[0] }; - - if ( $parameters{filename} ) { - - my $fh = IO::File->new_tmpfile; - $fh->write( $part->content ) or die $!; - $fh->seek( SEEK_SET, 0 ) or die $!; - - $c->req->uploads->{ $parameters{filename} } = { - fh => $fh, - size => ( stat $fh )[7], - type => $part->content_type - }; - - push( @params, $parameters{filename}, $fh ); - } - else { - push( @params, $parameters{name}, $part->content ); - } - } - } - - my $parameters = $c->req->parameters; - - while ( my ( $name, $value ) = splice( @params, 0, 2 ) ) { - - if ( exists $parameters->{$name} ) { - for ( $parameters->{$name} ) { - $_ = [$_] unless ref($_) eq "ARRAY"; - push( @$_, $value ); - } - } - else { - $parameters->{$name} = $value; - } - } -} - -=item $c->prepare_path - -=cut - -sub prepare_path { - my $c = shift; - - my $base; - { - my $scheme = $c->http->request->uri->scheme; - my $host = $c->http->request->uri->host; - my $port = $c->http->request->uri->port; - - $base = URI->new; - $base->scheme($scheme); - $base->host($host); - $base->port($port); - - $base = $base->canonical->as_string; - } - - my $path = $c->http->request->uri->path || '/'; - $path =~ s/^\///; - - $c->req->base($base); - $c->req->path($path); -} - -=item $c->prepare_request($r) - -=cut - -sub prepare_request { - my ( $c, $http ) = @_; - $c->http($http); -} - -=item $c->prepare_uploads - -=cut - -sub prepare_uploads { - my $c = shift; -} +use base 'Catalyst::Engine'; -=back +warn("You are loading Catalyst::Engine::HTTP explicitly. -=head1 SEE ALSO +This is almost certainly a bad idea, as Catalyst::Engine::HTTP +has been removed in this version of Catalyst. -L. +Please update your application's scripts with: -=head1 AUTHOR + catalyst.pl -force -scripts MyApp -Sebastian Riedel, C -Christian Hansen, C +to update your scripts to not do this.\n") unless $ENV{HARNESS_ACTIVE}; -=head1 COPYRIGHT +1; -This program is free software, you can redistribute it and/or modify it under -the same terms as Perl itself. +# This is here only as some old generated scripts require Catalyst::Engine::HTTP -=cut -1;