Hi,
On Sat, Jul 28, 2001 at 12:44:29PM -0400, Rocco Caputo wrote:
> On Fri, Jul 27, 2001 at 11:50:52PM -0400, undercut wrote:
> > I think this filter still could use some updating. It seems the
> > methods send_error, send_basic_header, and send_status_line will cause
> > a crash from strict refs since it calls the put method with a string
> > when it expects arrayref. All you have to do is send a bad request
> > (like 2 blank lines) and it will trigger the crash.
> >
> > Please keep up the great work.
> I've fixed this and checked the new code into the cvs repository. The
> fix required a small change in the way Filter::HTTPD handles errors.
> Instead of crashing outright, it returns an HTTP::Response object
> containing the error message.
>
> I've documented a suggested use in the Filter::HTTPD manpage. If
> ref($request) is "HTTP::Response", just put it directly and return.
> Otherwise the program has received a request and can parse it as
> usual.
Graaah! I have not been reading poe list for a couple of days,
encountered this same problem, and spent some time fixing it. :-(((
Well, tough luck, I guess...
Anyway. HTTPD.pm *still* requires some further fixing. First, it's not
HTTPD's business to die "Didn't want any more data"; I guess that 400
Bad Request is in order here as well. Second, I do believe it is not
HTTPD's business to print anything to stdout - it's great for
debugging, but does not work well in production. And third, there are
some `use of undefined value' occurences there at the moment.
This patch works for me, though you might prefer to make the absense of
the Content-Length header a 400 error, too:
--- src/poe/POE/Filter/HTTPD.pm Mon Jul 30 01:16:56 2001
+++ /usr/local/lib/perl5/site_perl/5.6.0/POE/Filter/HTTPD.pm Mon Jul 30 01:30:42
+2001
@@ -47,7 +47,8 @@
# happen. -><- Maybe this should return [] instead of dying?
if($self->{'finish'}) {
- die "Didn't want any more data\n";
+ # die "Didn't want any more data\n";
+ return [ $self->build_error(400, "Did not want any more data") ]; # BAD_REQUEST
}
# Accumulate data in a framing buffer.
@@ -61,12 +62,13 @@
if($self->{header}) {
my $buf = $self->{buffer};
my $r = $self->{header};
- if(length($buf) >= $r->content_length()) {
+ my $cl = $r->content_length() || "0 (implicit)";
+ if(length($buf) >= $cl) {
$r->content($buf);
$self->{finish}++;
return [$r];
} else {
- print $r->content_length()." wanted, got ".length($buf)."\n";
+# print "$cl wanted, got ".length($buf)."\n";
}
return [];
}
@@ -136,7 +138,8 @@
# print "post:$buf:\END BUFFER\n";
# print length($buf)."-".$r->content_length()."\n";
- if(length($buf) >= $r->content_length()) {
+ my $cl = $r->content_length() || 0;
+ if(length($buf) >= $cl) {
$r->content($buf);
$self->{finish}++;
return [$r];
@@ -222,6 +225,7 @@
$status ||= RC_BAD_REQUEST;
my $message = status_message($status) || "Unknown Error";
+ $details ||= '';
return
$self->build_basic_response
One minor note: if ($req->isa('HTTP::Response')) might look better than
if (ref($req) eq 'HTTP::Response') for OO purists; I think that the
docs could mention both forms.
=Anton.
--
May the tuna salad be with you.