Debian Codegraph @

lib/3rdParty/composer/symfony/http-client-contracts/Test/Fixtures/web/index.php

raw symbols SCIP
1 <?php
2
3 if ('cli-server' !== \PHP_SAPI) {
4 // safe guard against unwanted execution
5 throw new \Exception("You cannot run this script directly, it's a fixture for TestHttpServer.");
6 }
7
8 $vars = [];
9
10 if (!$_POST) {
11 $_POST = json_decode(file_get_contents('php://input'), true);
12 $_POST['content-type'] = $_SERVER['HTTP_CONTENT_TYPE'] ?? '?';
13 }
14
15 $headers = [
16 'SERVER_PROTOCOL',
17 'SERVER_NAME',
18 'REQUEST_URI',
19 'REQUEST_METHOD',
20 'PHP_AUTH_USER',
21 'PHP_AUTH_PW',
22 'REMOTE_ADDR',
23 'REMOTE_PORT',
24 ];
25
26 foreach ($headers as $k) {
27 if (isset($_SERVER[$k])) {
28 $vars[$k] = $_SERVER[$k];
29 }
30 }
31
32 foreach ($_SERVER as $k => $v) {
33 if (str_starts_with($k, 'HTTP_')) {
34 $vars[$k] = $v;
35 }
36 }
37
38 $json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
39
40 switch (parse_url($vars['REQUEST_URI'], \PHP_URL_PATH)) {
41 default:
42 exit;
43
44 case '/head':
45 header('X-Request-Vars: '.json_encode($vars, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE));
46 header('Content-Length: '.strlen($json), true);
47 break;
48
49 case '/':
50 case '/?a=a&b=b':
51 case 'http://127.0.0.1:8057/':
52 case 'http://localhost:8057/':
53 ob_start('ob_gzhandler');
54 break;
55
56 case '/103':
57 header('HTTP/1.1 103 Early Hints');
58 header('Link: </style.css>; rel=preload; as=style', false);
59 header('Link: </script.js>; rel=preload; as=script', false);
60 flush();
61 usleep(1000);
62 echo "HTTP/1.1 200 OK\r\n";
63 echo "Date: Fri, 26 May 2017 10:02:11 GMT\r\n";
64 echo "Content-Length: 13\r\n";
65 echo "\r\n";
66 echo 'Here the body';
67 exit;
68
69 case '/404':
70 header('Content-Type: application/json', true, 404);
71 break;
72
73 case '/404-gzipped':
74 header('Content-Type: text/plain', true, 404);
75 ob_start('ob_gzhandler');
76 @ob_flush();
77 flush();
78 usleep(300000);
79 echo 'some text';
80 exit;
81
82 case '/301':
83 if ('Basic Zm9vOmJhcg==' === $vars['HTTP_AUTHORIZATION']) {
84 header('Location: http://127.0.0.1:8057/302', true, 301);
85 }
86 break;
87
88 case '/301/bad-tld':
89 header('Location: http://foo.example.', true, 301);
90 break;
91
92 case '/301/invalid':
93 header('Location: //?foo=bar', true, 301);
94 break;
95
96 case '/301/proxy':
97 case 'http://localhost:8057/301/proxy':
98 case 'http://127.0.0.1:8057/301/proxy':
99 header('Location: http://localhost:8057/', true, 301);
100 break;
101
102 case '/302':
103 if (!isset($vars['HTTP_AUTHORIZATION'])) {
104 $location = $_GET['location'] ?? 'http://localhost:8057/';
105 header('Location: '.$location, true, 302);
106 }
107 break;
108
109 case '/302/relative':
110 header('Location: ..', true, 302);
111 break;
112
113 case '/304':
114 header('Content-Length: 10', true, 304);
115 echo '12345';
116
117 return;
118
119 case '/304/etag':
120 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
121 header('ETag: "abc123"', true, 304);
122 exit;
123 }
124 header('ETag: "abc123"');
125 break;
126
127 case '/307':
128 header('Location: http://localhost:8057/post', true, 307);
129 break;
130
131 case '/length-broken':
132 header('Content-Length: 1000');
133 break;
134
135 case '/post':
136 $output = json_encode($_POST + ['REQUEST_METHOD' => $vars['REQUEST_METHOD']], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
137 header('Content-Type: application/json', true);
138 header('Content-Length: '.strlen($output));
139 echo $output;
140 exit;
141
142 case '/timeout-header':
143 usleep(300000);
144 break;
145
146 case '/timeout-body':
147 echo '<1>';
148 @ob_flush();
149 flush();
150 usleep(500000);
151 echo '<2>';
152 exit;
153
154 case '/timeout-long':
155 ignore_user_abort(false);
156 sleep(1);
157 while (true) {
158 echo '<1>';
159 @ob_flush();
160 flush();
161 usleep(500);
162 }
163 exit;
164
165 case '/chunked':
166 header('Transfer-Encoding: chunked');
167 echo "8\r\nSymfony \r\n5\r\nis aw\r\n6\r\nesome!\r\n0\r\n\r\n";
168 exit;
169
170 case '/chunked-broken':
171 header('Transfer-Encoding: chunked');
172 echo "8\r\nSymfony \r\n5\r\nis aw\r\n6\r\ne";
173 exit;
174
175 case '/gzip-broken':
176 header('Content-Encoding: gzip');
177 echo str_repeat('-', 1000);
178 exit;
179
180 case '/max-duration':
181 ignore_user_abort(false);
182 while (true) {
183 echo '<1>';
184 @ob_flush();
185 flush();
186 usleep(500);
187 }
188 exit;
189
190 case '/json':
191 header('Content-Type: application/json');
192 echo json_encode([
193 'documents' => [
194 ['id' => '/json/1'],
195 ['id' => '/json/2'],
196 ['id' => '/json/3'],
197 ],
198 ]);
199 exit;
200
201 case '/json/1':
202 case '/json/2':
203 case '/json/3':
204 header('Content-Type: application/json');
205 echo json_encode([
206 'title' => $vars['REQUEST_URI'],
207 ]);
208
209 exit;
210
211 case '/custom':
212 if (isset($_GET['status'])) {
213 http_response_code((int) $_GET['status']);
214 }
215 if (isset($_GET['headers']) && is_array($_GET['headers'])) {
216 foreach ($_GET['headers'] as $header) {
217 header($header);
218 }
219 }
220 }
221
222 header('Content-Type: application/json', true);
223
224 echo $json;