X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FDaemon.pm;h=ec6ffcd3bc90367c93cbc476445bb7dac1afbeca;hb=d837e1a7eadff19ff04373ad19d22fa293e19db5;hp=b8e0a09f4e62a8481a2f06ee9c585b584dcda2fc;hpb=45374ac6977e9464410a8c7518fb26ab812258cb;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/HTTP/Daemon.pm b/lib/Catalyst/Engine/HTTP/Daemon.pm index b8e0a09..ec6ffcd 100644 --- a/lib/Catalyst/Engine/HTTP/Daemon.pm +++ b/lib/Catalyst/Engine/HTTP/Daemon.pm @@ -1,9 +1,9 @@ package Catalyst::Engine::HTTP::Daemon; use strict; -use base 'Catalyst::Engine::HTTP'; +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. +This class overloads some methods from C. =over 4 @@ -45,31 +43,43 @@ sub run { my $class = shift; my $port = shift || 3000; - my $daemon = Catalyst::Engine::HTTP::Daemon::Catalyst->new( + my $daemon = Catalyst::Engine::HTTP::Base::struct->new( + Listen => SOMAXCONN, LocalPort => $port, - ReuseAddr => 1 + ReuseAddr => 1, + Type => SOCK_STREAM, ); - unless ( $daemon ) { - die( "Failed to create daemon: $!\n" ); + unless ($daemon) { + die("Failed to create daemon: $!\n"); } - printf( "You can connect to your server at %s\n", $daemon->url ); + my $base = URI->new( $daemon->url )->canonical; + + printf( "You can connect to your server at %s\n", $base ); while ( my $connection = $daemon->accept ) { + $connection->timeout(5); + while ( my $request = $connection->get_request ) { $request->uri->scheme('http'); # Force URI::http + $request->uri->host( $request->header('Host') || $base->host ); + $request->uri->port( $base->port ); + + my $hostname = gethostbyaddr( $connection->peeraddr, AF_INET ); - my $http = Catalyst::Engine::HTTP::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($http); $connection->send_response( $http->response ); + } $connection->close; @@ -81,7 +91,8 @@ sub run { =head1 SEE ALSO -L, L. +L, L, L, +L. =head1 AUTHOR @@ -95,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'; @@ -105,4 +116,3 @@ sub product_tokens { } 1; -