Skip to content

Commit 6fea74d

Browse files
committed
Moved header case normalization to top
1 parent f1c00f0 commit 6fea74d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

proxy.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* @param zlib
77
*/
88

9-
// Get stuff
10-
$headers = getallheaders();
9+
// Get normalized headers and such
10+
$headers = array_change_key_case(getallheaders());
1111
$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;
1414

1515

1616

@@ -23,7 +23,7 @@
2323
failure(400, "Not an absolute URL: $url");
2424

2525
// 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'])
2727
failure(403, "Invalid referer");
2828

2929
// Check whitelist, if not empty
@@ -32,21 +32,26 @@
3232

3333

3434

35-
// Remove ignored headers and prepare the rest for resending
35+
// Remove ignored headers
3636
$ignore = [
3737
'cookie',
3838
'content-length',
3939
'host',
4040
'x-proxy-url',
4141
'x-proxy-cookie',
4242
];
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
4446
if($cookie)
4547
$headers['Cookie'] = $cookie;
48+
49+
// Format headers for curl
4650
foreach($headers as $key => &$value)
4751
$value = ucwords($key, '-').": $value";
4852

4953

54+
5055
// Init curl
5156
$curl = curl_init();
5257
$maxredirs = $opts[CURLOPT_MAXREDIRS] ?? 20;

0 commit comments

Comments
 (0)