Subject: | Filter dies with "Wrong version" on big POST requests |
When fastcgi request is fetched from socket by more than one read(2)
call, filters tries to interpret parts of POSTDATA as fastcgi protocol,
resulting in "Wrong version" error. With attached patch all works ok.
versions of software:
POE::Component::FastCGI version is 0.1
Perl v5.8.8 built for x86_64-linux-gnu-thread-multi
Linux lanfear 2.6.24-1-amd64
nginx 0.5.35 as a web server
Subject: | poe-fcgi.diff |
--- /home/binarin/compose-test/cgi-bin/POE/Filter/FastCGI.pm 2008-03-17 10:45:36.000000000 +0300
+++ FastCGI.pm 2008-03-24 14:43:59.000000000 +0300
@@ -24,6 +24,7 @@
package POE::Filter::FastCGI;
use strict;
use bytes;
+use Data::Dumper;
our(@ROLE, @TYPE);
@@ -73,11 +74,11 @@
return $self;
}
-sub get {
- my($self, $stream) = @_;
- $self->get_one_start($stream);
- return $self->get_one;
-}
+# sub get {
+# my($self, $stream) = @_;
+# $self->get_one_start($stream);
+# return $self->get_one;
+# }
sub get_pending {
my($self) = @_;
@@ -87,7 +88,7 @@
sub get_one {
my($self) = @_;
my @output = ( );
-
+
while($self->{buffer}) {
if($self->{state} == STATE_WAIT) {
return [ ] unless length $self->{buffer} >= HEADER_LENGTH;
@@ -99,7 +100,7 @@
unpack "CCnnC", $header;
die "Wrong version" if $self->{version} != FCGI_VERSION_1;
-
+
if($self->{contentlen}) {
$self->{state} = STATE_DATA;
}else{
@@ -126,7 +127,7 @@
sub get_one_start {
my($self, $stream) = @_;
- $self->{buffer} = join '', @$stream;
+ $self->{buffer} .= join '', @$stream;
}
# Process FastCGI record