X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FHTTP%2FDaemon.pm;h=bcfd4c8c9271af513226f7f2c8b5c1ee4e7e8916;hb=e2fd5b5f162a33895ad401a8d31fca481c478a8c;hp=65129eee71c314358e4e16d259753534bab66fe4;hpb=d96e14c21fb544597f459aaaad969c34af7f2d1f;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine/HTTP/Daemon.pm b/lib/Catalyst/Engine/HTTP/Daemon.pm index 65129ee..bcfd4c8 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::LWP'; +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::Catalyst->new( + Listen => SOMAXCONN, LocalPort => $port, - ReuseAddr => 1 + ReuseAddr => 1, + Type => SOCK_STREAM, ); 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 $lwp = Catalyst::Engine::LWP::HTTP->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; @@ -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';