use strict;
use base 'Catalyst::Engine::Test';
-use IO::Socket qw(AF_INET SOCK_STREAM SOMAXCONN);
+use IO::Socket qw(AF_INET INADDR_ANY SOCK_STREAM SOMAXCONN);
=head1 NAME
Listen => SOMAXCONN,
LocalPort => $port,
ReuseAddr => 1,
- Timeout => .1,
Type => SOCK_STREAM,
);
printf( "You can connect to your server at %s\n", $base );
- while ( 1 ) {
+ while ( my $connection = $daemon->accept ) {
- my $connection = $daemon->accept or next;
+ $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::Test::HTTP->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;