CC: | "Paul T. Seamons" <paul [...] seamons.com> |
Subject: | Net::Server::HTTP - Sending of custom status does not work |
Date: | Fri, 3 Aug 2012 11:43:11 +0200 |
To: | bug-Net-Server [...] rt.cpan.org |
From: | Gregor Kleen <gkleen [...] praseodym.org> |
When using the package, as it is currently on cpan the following perl
code answers querys with status '200 OK'. Expected behaviour would be
to answer '404 Not found'.
#!/usr/bin/perl
# This is test.pl
# The following command was used to inspect returned headers:
# wget -q -O - -S --no-proxy 'localhost:8080'
use strict;
use warnings;
package bugtest;
use HTTP;
use base qw(Net::Server::HTTP);
sub process_http_request
{
my $self = shift;
$self->send_status(404, 'Not found');
print "Content-type: text/plain\r\n\r\n404\r\n";
}
__PACKAGE__->run(
port => 8080
);
return 1;
The problem seems to be the regular expression in line 93 not
recognizing the Status lines produced by send_status(). This is easily
fixed with the following patch.
diff --git a/HTTP.pm b/HTTP.pm
index b3511a7..32251a6 100644
--- a/HTTP.pm
+++ b/HTTP.pm
@@ -90,7 +90,7 @@ sub pre_bind {
}
${*$client}{'headers_sent'} = 1;
delete ${*$client}{'headers'};
- if ($headers =~ m{^HTTP/1.[01] \s+ \d+ (?: | \s+ .+)\r?\n}) {
+ if ($headers =~ m{^HTTP/1.[01] \s+ \d+ (?: | \s+ .+)\r?\n}x) {
# looks like they are sending their own status
}
elsif ($headers =~ /^Status:\s+(\d+) (?:|\s+(.+?))\s*$/im) {
The patch has also been attached to this mail.
Message body is not shown because sender requested not to inline it.
Message body not shown because it is not plain text.