Skip Menu |

This queue is for tickets about the POE-Component-Server-HTTP CPAN distribution.

Report information
The Basics
Id: 8793
Status: resolved
Priority: 0/
Queue: POE-Component-Server-HTTP

People
Owner: Nobody in particular
Requestors: liste [...] artware.qc.ca
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Date: Wed, 08 Dec 2004 23:21:36 -0500 (EST)
From: liste [...] artware.qc.ca
To: bug-poe-component-server-http [...] rt.cpan.org
Subject: Patch to POE::Component::Server::HTTP
Large patch to PoCo::Server::HTTP : Renamed t/compile.t to t/00_compile.t Added t/10_run.t Added t/30_error.t Added support for ErrorHandler Added DEBUG messages to HTTP.pm Added ->is_error to response and request objects Renamed Handler to Queue to minimize confusion in code. Cleaned up sub execute {} where $state was being set at funny places Reorganized Map, for ErrorHandler and so that filenames don't get a trailing / ->create() now returns a hashref, keys are httpd or tcp, values are the session aliases of the respective sessions. -Philip

Message body is not shown because sender requested not to inline it.

From: mrdamnfrenchy [...] yahoo.com
It would be nice if there was a default ErrorHandler that outputted more than this: Can't use string ("") as a subroutine ref while "strict refs" in use at POE/Component/Server/HTTP.pm line 309. [liste@artware.qc.ca - Wed Dec 8 23:28:14 2004]: Show quoted text
> Large patch to PoCo::Server::HTTP : > > Renamed t/compile.t to t/00_compile.t > Added t/10_run.t > Added t/30_error.t > Added support for ErrorHandler > Added DEBUG messages to HTTP.pm > Added ->is_error to response and request objects > Renamed Handler to Queue to minimize confusion in code. > Cleaned up sub execute {} where $state was being set at funny
places Show quoted text
> Reorganized Map, for ErrorHandler and so that filenames don't
get a Show quoted text
> trailing / > ->create() now returns a hashref, keys are httpd or tcp, values > are the session aliases of the respective sessions. > > -Philip
From: Philip Gwyn
[guest - Mon Dec 13 20:50:59 2004]: Show quoted text
> It would be nice if there was a default ErrorHandler that outputted > more than this: > > Can't use string ("") as a subroutine ref while "strict refs" in use > at POE/Component/Server/HTTP.pm line 309.
Hehe! OK. This second patch must be applied after the first. Should I also upload a merged patch? 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
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;
Both patches applied to the repository. I've also fixed the keepalive check that you broke so it correctly handles keepalive for HTTP/1.1 again. I'll release to CPAN after the successor to POE 0.3005 is released, since to release now will just cause pain as POE::Filter::HTTP is broken in the current release. -- Richard Clamp <richardc@unixbeard.net>