--- CGI.pm-orig Wed Jul 25 19:15:49 2007 +++ CGI.pm Wed Jul 25 20:13:56 2007 @@ -605,6 +605,21 @@ last METHOD; } + if ($meth eq 'PUT') { + + if ( $content_length > 0 ) { + $self->read_from_client(\$query_string,$content_length,0); + } + else { + $self->read_from_stdin(\$query_string); + my($param) = 'POSTDATA' ; + $self->add_parameter($param) ; + push (@{$self->{$param}},$query_string); + undef $query_string ; + } + last METHOD; + } + # If $meth is not of GET, POST or HEAD, assume we're being debugged offline. # Check the command line and then the standard input for data. # We use the shellwords package in order to behave the way that @@ -625,8 +640,8 @@ && defined($ENV{'CONTENT_TYPE'}) && $ENV{'CONTENT_TYPE'} !~ m|^application/x-www-form-urlencoded| && $ENV{'CONTENT_TYPE'} !~ m|^multipart/form-data| ) { - my($param) = 'POSTDATA' ; - $self->add_parameter($param) ; + my($param) = 'POSTDATA' ; + $self->add_parameter($param) ; push (@{$self->{$param}},$query_string); undef $query_string ; } @@ -944,6 +959,47 @@ return $MOD_PERL ? $self->r->read($$buff, $len, $offset) : read(\*STDIN, $$buff, $len, $offset); +} +END_OF_FUNC + +'read_from_stdin' => <<'END_OF_FUNC', +# Read data from stdin until all is read +sub read_from_stdin { + my($self, $buff) = @_; + local $^W=0; # prevent a warning + +# +# TODO: loop over STDIN until all is read +# + + my($eoffound) = 0; + my($localbuf) = ''; + my($tempbuf) = ''; + my($bufsiz) = 1024; + my($res); + while ($eoffound == 0) { + if ( $MOD_PERL ) { + $res = $self->r->read($tempbuf, $bufsiz, 0) + } + else { + $res = read(\*STDIN, $tempbuf, $bufsiz); + } + + if ( !defined($res) ) { + # TODO: how to do error reporting ? + $eoffound = 1; + last; + } + if ( $res == 0 ) { + $eoffound = 1; + last; + } + $localbuf .= $tempbuf; + } + + $$buff = $localbuf; + + return $res; } END_OF_FUNC