From: Christian Hansen Date: Tue, 29 Mar 2005 20:55:04 +0000 (+0000) Subject: Fixing HTTP.pm X-Git-Tag: 5.7099_04~1655 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1a80619d839bc8dd6321648d8140a795bf85025e Fixing HTTP.pm --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 0513615..27dfb3d 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -444,8 +444,8 @@ sub prepare { } $c->prepare_request($r); $c->prepare_path; - $c->prepare_cookies; $c->prepare_headers; + $c->prepare_cookies; $c->prepare_connection; my $method = $c->req->method || ''; my $path = $c->req->path || ''; diff --git a/lib/Catalyst/Engine/HTTP.pm b/lib/Catalyst/Engine/HTTP.pm index 37be240..9332745 100644 --- a/lib/Catalyst/Engine/HTTP.pm +++ b/lib/Catalyst/Engine/HTTP.pm @@ -60,6 +60,8 @@ sub run { while ( my $connection = $daemon->accept ) { + $connection->timeout(5); + while ( my $request = $connection->get_request ) { $request->uri->scheme('http'); # Force URI::http @@ -67,13 +69,19 @@ sub run { $request->uri->port( $base->port ); my $lwp = Catalyst::Engine::Test::LWP->new( - request => $request, address => $connection->peerhost, - hostname => gethostbyaddr( $connection->peeraddr, AF_INET ) + hostname => gethostbyaddr( $connection->peeraddr, AF_INET ), + request => $request, + response => HTTP::Response->new ); $class->handler($lwp); $connection->send_response( $lwp->response ); + + if ( $class->debug ) { + $class->log->info( sprintf( "Peer %s:%d",$connection->peerhost, $connection->peerport ) ); + } + } $connection->close; diff --git a/lib/Catalyst/Engine/Test.pm b/lib/Catalyst/Engine/Test.pm index 93e8839..9127e71 100644 --- a/lib/Catalyst/Engine/Test.pm +++ b/lib/Catalyst/Engine/Test.pm @@ -57,9 +57,11 @@ This class overloads some methods from C. 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 ); + $c->lwp->response->code( $c->response->status || 200 ); + + for my $name ( $c->response->headers->header_field_names ) { + $c->lwp->response->header( $name => $c->response->header($name) ); + } while ( my ( $name, $cookie ) = each %{ $c->response->cookies } ) { my $cookie = CGI::Cookie->new( @@ -71,10 +73,8 @@ sub finalize_headers { -secure => $cookie->{secure} || 0 ); - $response->header( 'Set-Cookie' => $cookie->as_string ); + $c->lwp->response->header( 'Set-Cookie' => $cookie->as_string ); } - - $c->lwp->response($response); } =item $c->finalize_output @@ -103,7 +103,7 @@ sub prepare_connection { sub prepare_cookies { my $c = shift; - if ( my $header = $c->request->headers->header('Cookie') ) { + if ( my $header = $c->request->header('Cookie') ) { $c->req->cookies( { CGI::Cookie->parse($header) } ); } } @@ -246,9 +246,10 @@ sub run { } my $lwp = Catalyst::Engine::Test::LWP->new( - request => $request, address => '127.0.0.1', - hostname => 'localhost' + hostname => 'localhost', + request => $request, + response => HTTP::Response->new ); $class->handler($lwp);