Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / media / resources / serve-video.php
blob9bfcf0289d2bd43e237cbf4b7c31524221842a57
1 <?php
3 $fileName = $_GET["name"];
4 $type = $_GET["type"];
6 $fileSize = filesize($fileName);
7 $start = 0;
8 $end = $fileSize - 1;
9 $contentRange = $_SERVER["HTTP_RANGE"];
10 if (isset($contentRange) && empty($_GET["norange"])) {
11 $range = explode("-", substr($contentRange, strlen("bytes=")));
12 $start = intval($range[0]);
13 if (!empty($range[1]))
14 $end = intval($range[1]);
15 $httpStatus = "206 Partial Content";
16 } else
17 $httpStatus = "200 OK";
19 header("Status: " . $httpStatus);
20 header("HTTP/1.1 " . $httpStatus);
21 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
22 header("Pragma: no-cache");
23 header("Etag: " . '"' . $fileSize . "-" . filemtime($fileName) . '"');
24 header("Content-Type: " . $type);
25 header("Content-Length: " . ($end - $start) + 1);
26 if ($contentRange && empty($_GET["norange"])) {
27 header("Accept-Ranges: bytes");
28 header("Content-Range: bytes " . $start . "-" . $end . "/" . $fileSize);
30 header("Connection: close");
32 $chunkSize = 1024 * 256;
33 $offset = $start;
35 $fn = fopen($fileName, "rb");
36 fseek($fn, $offset, 0);
38 while (!feof($fn) && $offset <= $end && connection_status() == 0) {
39 $readSize = min($chunkSize, ($end - $offset) + 1);
40 $buffer = fread($fn, $readSize);
41 print($buffer);
42 flush();
43 $offset += $chunkSize;
45 fclose($fn);
47 exit;