Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / fetch-access-control.php
blob4ff7b75a982040aaa2e7b9a2a20038135e524127
1 <?php
2 header('X-ServiceWorker-ServerHeader: SetInTheServer');
4 $prefix = '';
5 // If PreflightTest is set:
6 // - Use PACAOrign, PACAHeaders, PACAMethods, PACACredentials, PACEHeaders,
7 // PAuth, PAuthFail and PSetCookie* parameters in preflight.
8 // - Use $_GET['PreflightTest'] as HTTP status code.
9 // - Check Access-Control-Request-Method/Headers headers with
10 // PACRMethod/Headers parameter, if set, in preflight.
11 if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS' && isset($_GET['PreflightTest'])) {
12 $prefix = 'P';
14 if (isset($_GET['PACRMethod']) &&
15 $_GET['PACRMethod'] !=
16 $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']) {
17 header("HTTP/1.1 400");
18 exit;
20 if (isset($_GET['PACRHeaders']) &&
21 $_GET['PACRHeaders'] !=
22 $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']) {
23 header("HTTP/1.1 400");
24 exit;
26 // Preflight must not include Cookie headers.
27 if (isset($_SERVER['HTTP_COOKIE'])) {
28 header("HTTP/1.1 400");
29 exit;
31 header("HTTP/1.1 {$_GET['PreflightTest']}");
34 if (isset($_GET[$prefix . 'ACAOrigin'])) {
35 $origins = explode(',', $_GET[$prefix . 'ACAOrigin']);
36 for ($i = 0; $i < sizeof($origins); ++$i)
37 header("Access-Control-Allow-Origin: " . $origins[$i], false);
39 if (isset($_GET[$prefix . 'ACAHeaders']))
40 header('Access-Control-Allow-Headers: ' . $_GET[$prefix . 'ACAHeaders']);
41 if (isset($_GET[$prefix . 'ACAMethods']))
42 header('Access-Control-Allow-Methods: ' . $_GET[$prefix . 'ACAMethods']);
43 if (isset($_GET[$prefix . 'ACACredentials']))
44 header('Access-Control-Allow-Credentials: ' .
45 $_GET[$prefix . 'ACACredentials']);
46 if (isset($_GET[$prefix . 'ACEHeaders']))
47 header('Access-Control-Expose-Headers: ' . $_GET[$prefix . 'ACEHeaders']);
48 if (isset($_GET[$prefix . 'SetCookie']))
49 header('Set-Cookie: cookie=' . $_GET[$prefix . 'SetCookie']);
50 if (isset($_GET[$prefix . 'SetCookie2']))
51 header('Set-Cookie2: cookie=' . $_GET[$prefix . 'SetCookie2']);
53 if ((isset($_GET[$prefix . 'Auth']) and !isset($_SERVER['PHP_AUTH_USER'])) ||
54 isset($_GET[$prefix . 'AuthFail'])) {
55 header('WWW-Authenticate: Basic realm="Restricted"');
56 header('HTTP/1.0 401 Unauthorized');
57 echo 'Authentication canceled';
58 exit;
61 if (isset($_GET['PNGIMAGE'])) {
62 header('Content-Type: image/png');
63 echo base64_decode(
64 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1B' .
65 'AACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAhSURBVDhPY3wro/KfgQLABKXJBqMG' .
66 'jBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=');
67 exit;
70 $username = 'undefined';
71 $password = 'undefined';
72 $cookie = 'undefined';
73 if (isset($_SERVER['PHP_AUTH_USER'])) {
74 $username = $_SERVER['PHP_AUTH_USER'];
76 if (isset($_SERVER['PHP_AUTH_PW'])) {
77 $password = $_SERVER['PHP_AUTH_PW'];
79 if (isset($_COOKIE['cookie'])) {
80 $cookie = $_COOKIE['cookie'];
83 $files = array();
84 foreach ($_FILES as $key => $file) {
85 $content = '';
86 $fp = fopen($file['tmp_name'], 'r');
87 if ($fp) {
88 $content = $file['size'] > 0 ? fread($fp, $file['size']) : '';
89 fclose($fp);
91 $files[] = array('key' => $key,
92 'name' => $file['name'],
93 'type' => $file['type'],
94 'error' => $file['error'],
95 'size' => $file['size'],
96 'content' => $content);
99 header('Content-Type: application/json');
100 $arr = array('jsonpResult' => 'success',
101 'method' => $_SERVER['REQUEST_METHOD'],
102 'headers' => getallheaders(),
103 'body' => file_get_contents('php://input'),
104 'files' => $files,
105 'get' => $_GET,
106 'post' => $_POST,
107 'username' => $username,
108 'password' => $password,
109 'cookie' => $cookie);
110 $json = json_encode($arr);
111 echo "report( $json );";