summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi')
-rwxr-xr-xLayoutTests/http/tests/resources/post-and-verify-hybrid.cgi86
1 files changed, 86 insertions, 0 deletions
diff --git a/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi b/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi
new file mode 100755
index 0000000..2cc826a
--- /dev/null
+++ b/LayoutTests/http/tests/resources/post-and-verify-hybrid.cgi
@@ -0,0 +1,86 @@
+#!/usr/bin/perl -w
+
+use Config;
+
+print "Content-type: text/plain\n\n";
+
+if ($ENV{'REQUEST_METHOD'} eq "POST") {
+ if ($ENV{'CONTENT_LENGTH'}) {
+ read(STDIN, $postData, $ENV{'CONTENT_LENGTH'}) || die "Could not get post data\n";
+ } else {
+ $postData = "";
+ }
+
+ @list = split(/&/, $ENV{'QUERY_STRING'});
+ @values;
+ $values{'start'} = 0;
+ $values{'length'} = -1;
+ $values{'convert_newlines'} = 0;
+ foreach $element (@list) {
+ ($key, $value) = split(/=/, $element);
+ $values{$key} = $value;
+ }
+
+ # 'items' parameter would look like:
+ # <items> := <item>(','<item>)*
+ # <item> := <file> | <data>
+ # <file> := "file":<file-path>
+ # <data> := "data":<data-string>
+ @items = split(/,/, $values{'items'});
+ $expectedData = "";
+ $readPos = $values{'start'};
+ $remainingLength = $values{'length'};
+ foreach $item (@items) {
+ my ($type, $data) = split(/:/, $item);
+ my $size;
+ if ($type eq "data") {
+ $data =~ s/%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
+ $size = length($data);
+ if ($readPos > 0) {
+ if ($readPos > $size) {
+ $readPos -= $size;
+ next;
+ }
+ $data = substr($data, $readPos);
+ }
+ $data = substr($data, 0, $remainingLength) if ($remainingLength > 0);
+ } else {
+ $path = $data;
+ open(FILE, $path) || next;
+ $size = -s $path;
+ if ($readPos > 0) {
+ if ($readPos > $size) {
+ $readPos -= $size;
+ next;
+ }
+ seek(FILE, $readPos, 0);
+ }
+ if ($remainingLength > 0) {
+ read(FILE, $data, $remainingLength);
+ } else {
+ local $/ = undef;
+ $data = <FILE>;
+ }
+ close(FILE);
+ }
+ $readPos -= $size;
+ $expectedData .= $data;
+ if ($remainingLength > 0) {
+ $remainingLength -= length($data);
+ last if $remainingLength <= 0;
+ }
+ }
+
+ if ($values{'convert_newlines'}) {
+ $nativeEnding = ($Config{osname} =~ /(MSWin|cygwin)/) ? "\r\n" : "\n";
+ $postData =~ s/$nativeEnding/[NL]/g;
+ }
+
+ if ($postData eq $expectedData) {
+ print "OK";
+ } else {
+ print "FAILED";
+ }
+} else {
+ print "Wrong method: " . $ENV{'REQUEST_METHOD'} . "\n";
+}