add $c->finalize_error and improve $c->finalize
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP.pm
index 3201ed9..0d73456 100644 (file)
@@ -3,7 +3,7 @@ package Catalyst::Engine::HTTP;
 use strict;
 use base 'Catalyst::Engine::Test';
 
-use IO::Socket qw(AF_INET);
+use IO::Socket qw(AF_INET INADDR_ANY SOCK_STREAM SOMAXCONN);
 
 =head1 NAME
 
@@ -44,8 +44,10 @@ sub run {
     my $port  = shift || 3000;
 
     my $daemon = Catalyst::Engine::HTTP::Catalyst->new(
+        Listen    => SOMAXCONN,
         LocalPort => $port,
-        ReuseAddr => 1
+        ReuseAddr => 1,
+        Type      => SOCK_STREAM,
     );
 
     unless ($daemon) {
@@ -58,20 +60,24 @@ sub run {
 
     while ( my $connection = $daemon->accept ) {
 
+        $connection->timeout(5);
+
         while ( my $request = $connection->get_request ) {
 
             $request->uri->scheme('http');    # Force URI::http
-            $request->uri->host( $base->host );
+            $request->uri->host( $request->header('Host') || $base->host );
             $request->uri->port( $base->port );
 
-            my $lwp = Catalyst::Engine::Test::LWP->new(
-                request  => $request,
+            my $http = Catalyst::Engine::Test::HTTP->new(
                 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 );
+            $class->handler($http);
+            $connection->send_response( $http->response );
+
         }
 
         $connection->close;