AnyEvent-HTTP-Server-II icon indicating copy to clipboard operation
AnyEvent-HTTP-Server-II copied to clipboard

Processing POST-data doesn't work

Open jari-omniata opened this issue 10 years ago • 0 comments

Suggesting following patch to make form work. Example code:

  return {
      # There will be a request-object as 1st parameter, but it cannot be used.
      form => sub { my (undef, $body) = @_; return do_post($request, $body) }
  };

Patch:

--- lib/AnyEvent/HTTP/Server.pm 2015-01-27 08:19:47.000000000 +0000
+++ perl-5.15.5/lib/site_perl/5.15.5/AnyEvent/HTTP/Server.pm      2015-01-27 15:15:44.000000000 +0000
@@ -490,6 +490,7 @@

                                                                                elsif (  exists $rv[0]{form} ) {
                                                                                        my $body = '';
+                                                                                       my $rq = $req; 
                                                                                        $r{on_body} = sub {
                                                                                                my ($last,$part) = @_;
                                                                                                if ( length($body) + length($$part) > $self->{max_body_size} ) {
@@ -497,7 +498,7 @@  
                                                                                                }
                                                                                                $body .= $$part;
                                                                                                if ($last) {
-                                                                                                       $rv[0]{form}( $req->form($body), $body );
+                                                                                                       $rv[0]{form}( $rq->form($body), $body );        
                                                                                                        delete $r{on_body};
                                                                                                }
                                                                                        };

This will fix the run-time error of $req being unset. The $req will be set to cb-code, but it is stale and really doesn't function.

jari-omniata avatar Jan 28 '15 13:01 jari-omniata