Simplify Request::getRequestHeaders()

This commit is contained in:
PJ Dietz 2014-07-08 20:21:23 -04:00
parent 08cf2f4ec2
commit 25c423e0ee
1 changed files with 6 additions and 21 deletions

View File

@ -90,29 +90,14 @@ class Request extends Message implements RequestInterface
return apache_request_headers(); return apache_request_headers();
} }
// If apache_request_headers is not available, use this, based on replacement code from // http://www.php.net/manual/en/function.getallheaders.php#84262
// the PHP manual. $headers = '';
foreach ($_SERVER as $name => $value) {
$arh = array(); if (substr($name, 0, 5) === 'HTTP_') {
$rx_http = '/\AHTTP_/'; $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
foreach ($_SERVER as $key => $val) {
if (preg_match($rx_http, $key)) {
$arh_key = preg_replace($rx_http, '', $key);
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
foreach ($rx_matches as $ak_key => $ak_val) {
$rx_matches[$ak_key] = ucfirst(
$ak_val
);
}
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
} }
} }
return $arh; return $headers;
} }
/** /**