From 25c423e0ee34c8671fc4a0de9fd0bd8ccadcd428 Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Tue, 8 Jul 2014 20:21:23 -0400 Subject: [PATCH] Simplify Request::getRequestHeaders() --- src/pjdietz/WellRESTed/Request.php | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/pjdietz/WellRESTed/Request.php b/src/pjdietz/WellRESTed/Request.php index 5c1b009..a8e3e0d 100644 --- a/src/pjdietz/WellRESTed/Request.php +++ b/src/pjdietz/WellRESTed/Request.php @@ -90,29 +90,14 @@ class Request extends Message implements RequestInterface return apache_request_headers(); } - // If apache_request_headers is not available, use this, based on replacement code from - // the PHP manual. - - $arh = array(); - $rx_http = '/\AHTTP_/'; - 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; + // http://www.php.net/manual/en/function.getallheaders.php#84262 + $headers = ''; + foreach ($_SERVER as $name => $value) { + if (substr($name, 0, 5) === 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } - return $arh; + return $headers; } /**