ソースを参照

Now with working POST method

Andy Baugh 5 年 前
コミット
51779f3361
2 ファイル変更6 行追加2 行削除
  1. 1 1
      js/pgupgrade.js
  2. 5 1
      lib/Troglodyne/CGI.pm

+ 1 - 1
js/pgupgrade.js

@@ -24,7 +24,7 @@ function doAPIRequestWithCallback (meth, mod, func, handler, errorHandler, args)
     } else if ( meth === 'POST' ) {
         oReq.open( meth, "api.cgi", true );
         oReq.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
-        oReq.send();
+        oReq.send(argstr);
     }
     return false;
 }

+ 5 - 1
lib/Troglodyne/CGI.pm

@@ -10,7 +10,11 @@ sub get_args {
     my $args_hr = {};
     my %handlers = (
         'GET'  => sub { return { map { split( /=/, $_ ) } split( /&/, $ENV{'QUERY_STRING'} ) } },
-        'POST' => sub { die "UNIMPLEMENTED!" },
+        'POST' => sub {
+            die "Content length longer than 4096 bytes on a POST. Get lost!" if $ENV{'CONTENT_LENGTH'} > 4096;
+            sysread( STDIN, my $line, $ENV{'CONTENT_LENGTH'} );
+            return { map { split( /=/, $_ ) } split( /&/, $line ) };
+        },
     );
     $args_hr = $handlers{$meth}->();
     return $args_hr;