+
+ my $method = $ENV{"REQUEST_METHOD"};
+ if (my $qs = $ENV{"QUERY_STRING"}) {
+ parse_raw_args($qs);
+ }
+ if ($method eq "GET" || $method eq "HEAD") {
+ } elsif ($method eq "POST") {
+ my $content_type = $ENV{"CONTENT_TYPE"} // "";
+ if ($content_type =~ /^application\/x-www-form-urlencoded\b/i) {
+ while (<STDIN>) {
+ chomp;
+ parse_raw_args($_);
+ }
+ } elsif ($content_type =~ /^multipart\/form-data\b/i) {
+ parse_multipart_form_data();
+ } else {
+ http_error "415 Unsupported Media Type";
+ exit;
+ }
+ } else {
+ http_error "405 Method Not Allowed", "Allow: GET, HEAD, PUT";
+ }
+}
+
+sub parse_args($) { # CAVEAT: attached files must be defined in the main arg table
+ my $args = shift @_;
+ if (!$main_arg_table) {
+ $main_arg_table = $args;
+ init_args();
+ }
+
+ for my $a (values %$args) {