Added SpeedyCGI, partly fixed HTTP::Daemon
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP / Daemon.pm
index 1e2a211..bcfd4c8 100644 (file)
@@ -1,9 +1,9 @@
 package Catalyst::Engine::HTTP::Daemon;
 
 use strict;
-use base 'Catalyst::Engine::Test';
+use base 'Catalyst::Engine::HTTP::Base';
 
-use IO::Socket qw(AF_INET);
+use IO::Socket qw(AF_INET INADDR_ANY SOCK_STREAM SOMAXCONN);
 
 =head1 NAME
 
@@ -15,9 +15,7 @@ A script using the Catalyst::Engine::HTTP::Daemon module might look like:
 
     #!/usr/bin/perl -w
 
-    BEGIN { 
-       $ENV{CATALYST_ENGINE} = 'HTTP::Daemon';
-    }
+    BEGIN {  $ENV{CATALYST_ENGINE} = 'HTTP::Daemon' }
 
     use strict;
     use lib '/path/to/MyApp/lib';
@@ -31,7 +29,7 @@ This is the Catalyst engine specialized for development and testing.
 
 =head1 OVERLOADED METHODS
 
-This class overloads some methods from C<Catalyst::Engine::Test>.
+This class overloads some methods from C<Catalyst::Engine::HTTP::Base>.
 
 =over 4
 
@@ -45,9 +43,11 @@ sub run {
     my $class = shift;
     my $port  = shift || 3000;
 
-    my $daemon = Catalyst::Engine::HTTP::Daemon::Catalyst->new(
+    my $daemon = Catalyst::Engine::HTTP::Catalyst->new(
+        Listen    => SOMAXCONN,
         LocalPort => $port,
-        ReuseAddr => 1
+        ReuseAddr => 1,
+        Type      => SOCK_STREAM,
     );
 
     unless ($daemon) {
@@ -60,20 +60,26 @@ 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 $hostname = gethostbyaddr( $connection->peeraddr, AF_INET );
 
-            my $lwp = Catalyst::Engine::Test::LWP->new(
-                request  => $request,
+            my $http = Catalyst::Engine::HTTP::Base::struct->new(
                 address  => $connection->peerhost,
-                hostname => gethostbyaddr( $connection->peeraddr, AF_INET )
+                hostname => $hostname || $connection->peerhost,
+                request  => $request,
+                response => HTTP::Response->new
             );
 
-            $class->handler($lwp);
-            $connection->send_response( $lwp->response );
+            $class->handler($http);
+            $connection->send_response( $http->response );
+
         }
 
         $connection->close;
@@ -85,7 +91,8 @@ sub run {
 
 =head1 SEE ALSO
 
-L<Catalyst>, L<HTTP::Daemon>.
+L<Catalyst>, L<Catalyst::Engine>, L<Catalyst::Engine::HTTP::Base>, 
+L<HTTP::Daemon>.
 
 =head1 AUTHOR
 
@@ -99,7 +106,7 @@ the same terms as Perl itself.
 
 =cut
 
-package Catalyst::Engine::HTTP::Daemon::Catalyst;
+package Catalyst::Engine::HTTP::Catalyst;
 
 use strict;
 use base 'HTTP::Daemon';