From 13b4415d94749f88406a1bfc0caba70abb46f829 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 2 Jun 2020 11:25:44 +0200 Subject: [PATCH] polyfill apache_request_headers for PHP <= 7.2 Beware, some headers might not get the proper casing Signed-off-by: Arthur Schiwon --- proxy.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/proxy.php b/proxy.php index 28dcc64..d95f615 100644 --- a/proxy.php +++ b/proxy.php @@ -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? @@ -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'");