summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/resources/load-and-stall.cgi
blob: 6837c12fa8672b920a318bb1dc8067c485243404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl -w

use CGI;
use File::stat;
use Time::HiRes;

$query = new CGI;
$name = $query->param('name');
$stallAt = $query->param('stallAt');
$stallFor = $query->param('stallFor');
$mimeType = $query->param('mimeType');

my $filesize = stat($name)->size;
print "Content-type: " . $mimeType . "\n"; 
print "Content-Length: " . $filesize . "\n\n";

open FILE, $name or die;
binmode FILE;
$total = 0;
my ($buf, $data, $n);
while (($n = read FILE, $data, 1024) != 0) {
    $total += $n;
    if ($total > $stallAt) {
        if (defined $stallFor) {
            Time::HiRes::sleep($stallFor)
        }
        last;
    }
    print $data;
}
close(FILE);