f0aa12dae7c1251e25d0895aa0c0170873214363
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / resources / load-and-stall.cgi
1 #!/usr/bin/perl -wT
2
3 use CGI;
4 use File::stat;
5 use Time::HiRes;
6
7 $query = new CGI;
8 $name = $query->param('name');
9 $stallAt = $query->param('stallAt');
10 $stallFor = $query->param('stallFor');
11 $mimeType = $query->param('mimeType');
12
13 my $filesize = stat($name)->size;
14 print "Content-type: " . $mimeType . "\n"; 
15 print "Content-Length: " . $filesize . "\n\n";
16
17 open FILE, $name or die;
18 binmode FILE;
19 $total = 0;
20 my ($buf, $data, $n);
21 while (($n = read FILE, $data, 1024) != 0) {
22     $total += $n;
23     if ($total > $stallAt) {
24         if (defined $stallFor) {
25             Time::HiRes::sleep($stallFor)
26         }
27         last;
28     }
29     print $data;
30 }
31 close(FILE);