Subject: | Two small bugs in response detection and content length parsing |
Attached is a patch to fix two small bugs. They are:
- It is assumed that an HTTP response header is followed by a space.
I have not checked the standards (maybe it is required) but in normal
practice some do not have a space and therefore HTTP-Parser assumes
they are broken
- Whitespace before or after the Content-Length header will fail the
numeric test, for obvious reasons. However, stripping any
leading/trailing whitespace fixes this and has no adverse effects.
A patch is attached which fixes these two issues. Maybe either or
both could be included in the next release.
Subject: | http-parser-patches.diff |
--- Parser.pm 2007-10-23 10:42:14.000000000 +0100
+++ Parser.pm 2007-10-29 13:05:33.000000000 +0000
@@ -228,7 +228,7 @@
my ($major, $minor);
# is it an HTTP response?
- if ($request =~ /^HTTP\/(\d+)\.(\d+) /i) {
+ if ($request =~ /^HTTP\/(\d+)\.(\d+)/i) {
die 'HTTP responses not allowed' unless $self->{response};
($major,$minor) = ($1,$2);
my (undef, $state, $msg) = split / /,$request;
@@ -263,6 +263,8 @@
# see what sort of content we have, if any
if(my $length = $obj->header('content_length')) {
+ $length =~ s/^\s+//;
+ $length =~ s/\s+$//;
die "bad content-length '$length'" unless $length =~ /^(\d+)$/;
$self->{state} = 'body';
return $self->_parse_body();