|
6 | 6 | * @param zlib
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -// Get stuff |
10 |
| -$headers = getallheaders(); |
| 9 | +// Get normalized headers and such |
| 10 | +$headers = array_change_key_case(getallheaders()); |
11 | 11 | $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
12 |
| -$url = $headers['X-Proxy-Url'] ?? null; |
13 |
| -$cookie = $headers['X-Proxy-Cookie'] ?? null; |
| 12 | +$url = $headers['x-proxy-url'] ?? null; |
| 13 | +$cookie = $headers['x-proxy-cookie'] ?? null; |
14 | 14 |
|
15 | 15 |
|
16 | 16 |
|
|
23 | 23 | failure(400, "Not an absolute URL: $url");
|
24 | 24 |
|
25 | 25 | // Check referer hostname
|
26 |
| -if( ! parse_url($headers['Referer'] ?? null, PHP_URL_HOST) == $_SERVER['HTTP_HOST']) |
| 26 | +if( ! parse_url($headers['referer'] ?? null, PHP_URL_HOST) == $_SERVER['HTTP_HOST']) |
27 | 27 | failure(403, "Invalid referer");
|
28 | 28 |
|
29 | 29 | // Check whitelist, if not empty
|
|
32 | 32 |
|
33 | 33 |
|
34 | 34 |
|
35 |
| -// Remove ignored headers and prepare the rest for resending |
| 35 | +// Remove ignored headers |
36 | 36 | $ignore = [
|
37 | 37 | 'cookie',
|
38 | 38 | 'content-length',
|
39 | 39 | 'host',
|
40 | 40 | 'x-proxy-url',
|
41 | 41 | 'x-proxy-cookie',
|
42 | 42 | ];
|
43 |
| -$headers = array_diff_key(array_change_key_case($headers), array_flip($ignore)); |
| 43 | +$headers = array_diff_key($headers, array_flip($ignore)); |
| 44 | + |
| 45 | +// Set proxied cookie if we got one |
44 | 46 | if($cookie)
|
45 | 47 | $headers['Cookie'] = $cookie;
|
| 48 | + |
| 49 | +// Format headers for curl |
46 | 50 | foreach($headers as $key => &$value)
|
47 | 51 | $value = ucwords($key, '-').": $value";
|
48 | 52 |
|
49 | 53 |
|
| 54 | + |
50 | 55 | // Init curl
|
51 | 56 | $curl = curl_init();
|
52 | 57 | $maxredirs = $opts[CURLOPT_MAXREDIRS] ?? 20;
|
|
0 commit comments