diff -burN POE-Component-Server-HTTP-0.0501/Changes POE-Component-Server-HTTP-0.05-PG/Changes
--- POE-Component-Server-HTTP-0.0501/Changes 2004-12-08 23:58:06.000000000 -0500
+++ POE-Component-Server-HTTP-0.05-PG/Changes 2004-12-15 14:25:05.000000000 -0500
@@ -1,5 +1,10 @@
Revision history for Perl extension POE::Component::Server::HTTP.
+0.0502 Wednesday 15th Dec, 2004
+ Added status messages to t/10_run.t
+ Added default ErrorHandler, that prints a simple message to STDERR
+ Improved detection of keepalive close
+
0.0501 Wednesday 8th Dec, 2004
Renamed t/compile.t to t/00_compile.t
Added t/10_run.t
diff -burN POE-Component-Server-HTTP-0.0501/lib/POE/Component/Server/HTTP.pm POE-Component-Server-HTTP-0.05-PG/lib/POE/Component/Server/HTTP.pm
--- POE-Component-Server-HTTP-0.0501/lib/POE/Component/Server/HTTP.pm 2004-12-09 00:00:17.000000000 -0500
+++ POE-Component-Server-HTTP-0.05-PG/lib/POE/Component/Server/HTTP.pm 2004-12-15 14:27:04.000000000 -0500
@@ -19,7 +19,7 @@
use POE::Component::Server::TCP;
use Sys::Hostname qw(hostname);
-$VERSION = "0.0501";
+$VERSION = "0.0502";
use POE::Component::Server::HTTP::Response;
use POE::Component::Server::HTTP::Request;
@@ -41,7 +41,9 @@
$self->{Headers} = { %default_headers, ($self->{Headers} ? %{$self->{Headers}}: ())};
$self->{TransHandler} = [] unless($self->{TransHandler});
- $self->{ErrorHandler} = {} unless($self->{ErrorHandler});
+ $self->{ErrorHandler} = {
+ '/' => \&default_http_error
+ } unless($self->{ErrorHandler});
$self->{PreHandler} = {} unless($self->{PreHandler});
$self->{PostHandler} = {} unless($self->{PostHandler});
@@ -59,6 +61,7 @@
# DWIM on these handlers
foreach my $phase (qw(PreHandler PostHandler)) {
+ # NOTE: we want the following 2 cases to fall through to the last case
if('CODE' eq ref $self->{$phase}) { # CODE to { / => [ CODE ]}
$self->{$phase}={'/' => [$self->{$phase}]};
}
@@ -141,6 +144,7 @@
)];
}
+# Set up queue for handling this request
sub rebuild_queue {
my($self, $handlers)=@_;
my $now=$handlers->{Queue}[0]; # what phase are we about to do?
@@ -181,7 +185,8 @@
PreHandler => [],
ContentHandler => undef,
PostHandler => [],
- Queue => $self->handler_queue,
+ # IMHO, Queue should be set in 'input' --PG
+ Queue => $self->handler_queue
};
my $wheel = POE::Wheel::ReadWrite->new(
@@ -271,6 +276,19 @@
}
}
+sub default_http_error
+{
+ my($request, $response)=@_;
+
+ my $op=$request->header('Operation');
+ my $errstr=$request->header('Error');
+ my $errnum=$request->header('Errnum');
+ return if $errnum==0 and $op eq 'read'; # socket closed
+
+ warn "Error during HTTP $op: $errstr ($errnum)\n";
+
+}
+
sub execute {
my $id = $_[ARG0];
@@ -299,6 +317,7 @@
last;
} elsif ($state eq 'ContentHandler' or
$state eq 'ErrorHandler') {
+
# XXX: we should wrap this in an eval and return 500
my $retvalue = $handlers->{$state}->($request, $response);
shift @{$handlers->{Queue}};
@@ -322,24 +341,36 @@
delete($response->{connection});
delete($request->{connection});
- if ( not $request->is_error and
- $request->protocol eq 'HTTP/1.1' and
- $request->header('Connection') ne 'close' ) { # keepalive
+ my $close=1;
+ my $conn=$request->header('Connection');
+
+ if($conn and not $request->is_error and
+ $request->protocol eq 'HTTP/1.1') {
+ $close=0; # keepalive
+ # It turns out the connection field can contain multiple
+ # comma separated values
+ $close=1 if qq(,$conn,) =~ /,\s*close\s*,/;
+ }
+
+ unless($close) {
+ DEBUG and warn "Keepalive connection still active";
# I'm probably going to burn for this violation
# of encapsulation --richardc
my $httpd_filter = $_[HEAP]{wheels}{$id}[2];
%{ $httpd_filter } = ( type => 0,
buffer => '',
finish => 0 );
+ # IMHO, Queue should be set in 'input' --PG
$handlers->{Queue} = $self->handler_queue;
}
else {
+ DEBUG and warn "Close connection";
delete($connection->{handlers});
delete($connection->{wheel});
delete($_[HEAP]->{c}->{$id});
delete($_[HEAP]->{wheels}->{$id});
}
- last;
+ last HANDLERS;
} elsif ($state eq 'Streaming') {
print "Streaming mode\n";
$self->{StreamHandler}->($request, $response);
@@ -363,7 +394,6 @@
shift @{$handlers->{Queue}};
last unless(0 != @{$handlers->{Queue}});
}
-
}
sub state_Map {
diff -burN POE-Component-Server-HTTP-0.0501/t/10_run.t POE-Component-Server-HTTP-0.05-PG/t/10_run.t
--- POE-Component-Server-HTTP-0.0501/t/10_run.t 2004-12-08 23:58:06.000000000 -0500
+++ POE-Component-Server-HTTP-0.05-PG/t/10_run.t 2004-12-15 13:21:18.000000000 -0500
@@ -34,23 +34,24 @@
my $req=HTTP::Request->new(GET => "
http://localhost:$PORT/");
my $resp=$UA->request($req);
- ok($resp->is_success) or die "resp=", Denter $resp;
+ ok($resp->is_success, "got index") or die "resp=", Denter $resp;
my $content=$resp->content;
- ok($content =~ /this is top/);
+ ok($content =~ /this is top/, "got top index");
$req=HTTP::Request->new(GET => "
http://localhost:$PORT/honk/something.html");
$resp=$UA->request($req);
- ok($resp->is_success);
+ ok($resp->is_success, "got something");
$content=$resp->content;
- ok($content =~ /this is honk/);
+ ok($content =~ /this is honk/, "something honked");
$req=HTTP::Request->new(GET => "
http://localhost:$PORT/bonk/zip.html");
$resp=$UA->request($req);
- ok($resp->is_success and $resp->content_type eq 'text/html');
+ ok(($resp->is_success and $resp->content_type eq 'text/html'),
+ "get text/html");
$content=$resp->content;
- ok($content =~ /my friend/);
+ ok($content =~ /my friend/, 'my friend');
}
@@ -66,7 +67,7 @@
'/bonk/zip.html' => \&bonk2,
# '/shutdown.html' => \&shutdown
},
- ErrorHandler => { '/' => \&error },
+# ErrorHandler => { '/' => \&error },
Headers => { Server => 'TestServer' },
);
$poe_kernel->run;