Skip to content

Commit

Permalink
polyfill apache_request_headers for PHP <= 7.2
Browse files Browse the repository at this point in the history
Beware, some headers might not get the proper casing

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz authored and kendy committed Jun 2, 2020
1 parent a218bb4 commit 13b4415
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ function startsWith($string, $with) {
return (substr($string, 0, strlen($with)) === $with);
}

if (!function_exists('getallheaders'))
{
// polyfill, e.g. on PHP 7.2 setups with nginx.
// Can be removed when 7.2 becomes unsupported
function getallheaders()
{
$headers = [];
if (!is_array($_SERVER)) {
return $headers;
}
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}

// avoid unwanted escaping of req= parameter
$request = $_SERVER['QUERY_STRING'];
// only asking for status?
Expand Down Expand Up @@ -240,7 +259,7 @@ function startsWith($string, $with) {
}

// Fetch our headers for later
$headers = apache_request_headers();
$headers = getallheaders();

$proxyURL .= $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?req=';
debug_log("ProxyPrefix: '$proxyURL'");
Expand Down

0 comments on commit 13b4415

Please sign in to comment.