Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / fetch-access-control.php
1 <?php
2 header('X-ServiceWorker-ServerHeader: SetInTheServer');
3 if (isset($_GET['ACAOrigin'])) {
4     $origins = explode(',', $_GET['ACAOrigin']);
5     for ($i = 0; $i < sizeof($origins); ++$i)
6         header("Access-Control-Allow-Origin: " . $origins[$i], false);
7 }
8
9 if (isset($_GET['ACAHeaders']))
10     header("Access-Control-Allow-Headers: {$_GET['ACAHeaders']}");
11 if (isset($_GET['ACAMethods']))
12     header("Access-Control-Allow-Methods: {$_GET['ACAMethods']}");
13 if (isset($_GET['ACACredentials']))
14     header("Access-Control-Allow-Credentials: {$_GET['ACACredentials']}");
15 if (isset($_GET['ACEHeaders']))
16     header("Access-Control-Expose-Headers: {$_GET['ACEHeaders']}");
17
18 if ((isset($_GET['Auth']) and !isset($_SERVER['PHP_AUTH_USER'])) || isset($_GET['AuthFail'])) {
19     header('WWW-Authenticate: Basic realm="Restricted"');
20     header('HTTP/1.0 401 Unauthorized');
21     echo 'Authentication canceled';
22     exit;
23 }
24
25 if (isset($_GET['PNGIMAGE'])) {
26   header('Content-Type: image/png');
27   echo base64_decode(
28     'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1B' .
29     'AACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAhSURBVDhPY3wro/KfgQLABKXJBqMG' .
30     'jBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=');
31   exit;
32 }
33
34 $username = 'undefined';
35 $password = 'undefined';
36 $cookie = 'undefined';
37 if (isset($_SERVER['PHP_AUTH_USER'])) {
38     $username = $_SERVER['PHP_AUTH_USER'];
39 }
40 if (isset($_SERVER['PHP_AUTH_PW'])) {
41     $password = $_SERVER['PHP_AUTH_PW'];
42 }
43 if (isset($_COOKIE['cookie'])) {
44     $cookie = $_COOKIE['cookie'];
45 }
46
47 $files = array();
48 foreach ($_FILES as $key => $file) {
49     $content = '';
50     $fp = fopen($file['tmp_name'], 'r');
51     if ($fp) {
52         $content = $file['size'] > 0 ? fread($fp, $file['size']) : '';
53         fclose($fp);
54     }
55     $files[] = array('key' => $key,
56                      'name' => $file['name'],
57                      'type' => $file['type'],
58                      'error' => $file['error'],
59                      'size' => $file['size'],
60                      'content' => $content);
61 }
62
63 header('Content-Type: application/json');
64 $arr = array('jsonpResult' => 'success',
65              'method' => $_SERVER['REQUEST_METHOD'],
66              'headers' => getallheaders(),
67              'body' => file_get_contents('php://input'),
68              'files' => $files,
69              'get' => $_GET,
70              'post' => $_POST,
71              'username' => $username,
72              'password' => $password,
73              'cookie' => $cookie);
74 $json = json_encode($arr);
75 echo "report( $json );";
76 ?>