Don't run the moose controller test if Moose isn't available
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP.pm
index 725992e..6f66a39 100644 (file)
@@ -11,7 +11,6 @@ use NEXT;
 use Socket;
 use IO::Socket::INET ();
 use IO::Select       ();
-use POSIX ":sys_wait_h";
 
 # For PAR
 require Catalyst::Engine::HTTP::Restarter;
@@ -190,7 +189,7 @@ sub run {
     }
 
     my $restart = 0;
-    local $SIG{CHLD} = \&_REAPER;
+    local $SIG{CHLD} = 'IGNORE';
 
     my $allowed = $options->{allowed} || { '127.0.0.1' => '255.255.255.255' };
     my $addr = $host ? inet_aton($host) : INADDR_ANY;
@@ -264,14 +263,15 @@ sub run {
             
             if ( !$self->_read_headers ) {
                 # Error reading, give up
+                close Remote;
                 next LISTEN;
             }
 
             my ( $method, $uri, $protocol ) = $self->_parse_request_line;
+            
+            next unless $method;
         
             DEBUG && warn "Parsed request: $method $uri $protocol\n";
-        
-            next unless $method;
 
             unless ( uc($method) eq 'RESTART' ) {
 
@@ -334,7 +334,7 @@ sub run {
         use Config;
         $ENV{PERL5LIB} .= join $Config{path_sep}, @INC; 
         
-        exec $^X . ' "' . $0 . '" ' . join( ' ', @{ $options->{argv} } );
+        exec $^X, $0, @{ $options->{argv} };
     }
 
     exit;
@@ -420,9 +420,14 @@ sub _read_headers {
     
     while (1) {
         my $read = sysread Remote, my $buf, CHUNKSIZE;
-    
-        if ( !$read ) {
-            DEBUG && warn "EOF or error: $!\n";
+        
+        if ( !defined $read ) {
+            next if $! == EWOULDBLOCK;
+            DEBUG && warn "Error reading headers: $!\n";
+            return;
+        }
+        elsif ( $read == 0 ) {
+            DEBUG && warn "EOF\n";
             return;
         }
     
@@ -438,7 +443,8 @@ sub _parse_request_line {
     my $self = shift;
 
     # Parse request line    
-    if ( $self->{inputbuf} !~ s/^(\w+)[ \t]+(\S+)(?:[ \t]+(HTTP\/\d+\.\d+))?[^\012]*\012// ) {
+    # Leading CRLF sometimes sent by buggy IE versions
+    if ( $self->{inputbuf} !~ s/^(?:\x0D\x0A)?(\w+)[ \t]+(\S+)(?:[ \t]+(HTTP\/\d+\.\d+))?[^\012]*\012// ) {
         return ();
     }
     
@@ -526,25 +532,13 @@ sub _socket_data {
 
 sub _inet_addr { unpack "N*", inet_aton( $_[0] ) }
 
-sub _REAPER {
-    my $child;
-    while ( ( $child = waitpid( -1,WNOHANG ) ) > 0 ) { }
-    $SIG{CHLD} = \&_REAPER;
-}
-
 =head1 SEE ALSO
 
-L<Catalyst>, L<Catalyst::Engine>.
+L<Catalyst>, L<Catalyst::Engine>
 
 =head1 AUTHORS
 
-Sebastian Riedel, <sri@cpan.org>
-
-Dan Kubb, <dan.kubb-cpan@onautopilot.com>
-
-Sascha Kiefer, <esskar@cpan.org>
-
-Andy Grundman, <andy@hybridized.org>
+Catalyst Contributors, see Catalyst.pm
 
 =head1 THANKS