5 print "Content-type: text/plain\n\n";
7 if ($ENV{'REQUEST_METHOD'} eq "POST") {
8 if ($ENV{'CONTENT_LENGTH'}) {
9 read(STDIN
, $postData, $ENV{'CONTENT_LENGTH'}) || die "Could not get post data\n";
14 @list = split(/&/, $ENV{'QUERY_STRING'});
17 $values{'length'} = -1;
18 $values{'convert_newlines'} = 0;
19 foreach $element (@list) {
20 ($key, $value) = split(/=/, $element);
21 $values{$key} = $value;
24 # 'items' parameter would look like:
25 # <items> := <item>(','<item>)*
26 # <item> := <file> | <data>
27 # <file> := "file":<file-path>
28 # <data> := "data":<data-string>
29 @items = split(/,/, $values{'items'});
31 $readPos = $values{'start'};
32 $remainingLength = $values{'length'};
33 foreach $item (@items) {
34 my ($type, $data) = split(/:/, $item);
36 if ($type eq "data") {
37 $data =~ s/%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
38 $size = length($data);
40 if ($readPos > $size) {
44 $data = substr($data, $readPos);
46 $data = substr($data, 0, $remainingLength) if ($remainingLength > 0);
49 open(FILE
, $path) || next;
52 if ($readPos > $size) {
56 seek(FILE
, $readPos, 0);
58 if ($remainingLength > 0) {
59 read(FILE
, $data, $remainingLength);
67 $expectedData .= $data;
68 if ($remainingLength > 0) {
69 $remainingLength -= length($data);
70 last if $remainingLength <= 0;
74 if ($values{'convert_newlines'}) {
75 $nativeEnding = ($Config{osname
} =~ /(MSWin|cygwin)/) ?
"\r\n" : "\n";
76 $postData =~ s/$nativeEnding/[NL]/g;
79 if ($postData eq $expectedData) {
85 print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n";