From ca0ae9bca6fea1a8ef924104b09649e41ea5ab36 Mon Sep 17 00:00:00 2001 From: "GODZilla0480@gmail.com" <> Date: Sun, 28 Aug 2011 09:06:28 +0000 Subject: Add method getHeaders to THttpRequest & THttpResponse --- framework/Web/THttpRequest.php | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'framework/Web/THttpRequest.php') diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 6529fdae..142b5813 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -343,7 +343,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar */ public function getIsSecureConnection() { - return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); + return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); } /** @@ -370,6 +370,32 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar return isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:''; } + /** + * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default) + * @return array + */ + public function getHeaders($case=null) + { + static $result; + + if($result === null && function_exists('apache_request_headers')) { + $result = apache_request_headers(); + } + elseif($result === null) { + $result = array(); + foreach($_SERVER as $key=>$value) { + if(strncasecmp($key, 'HTTP_', 5) !== 0) continue; + $key = str_replace(' ','-', ucwords(strtolower(str_replace('_',' ', substr($key, 5))))); + $result[$key] = $value; + } + } + + if($case !== null) + return array_change_key_case($result, $case); + + return $result; + } + /** * @return string part of that request URL after the host info (including pathinfo and query string) */ @@ -455,14 +481,14 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar */ public function getBrowser() { - try - { - return get_browser(); - } - catch(TPhpErrorException $e) - { - throw new TConfigurationException('httprequest_browscap_required'); - } + try + { + return get_browser(); + } + catch(TPhpErrorException $e) + { + throw new TConfigurationException('httprequest_browscap_required'); + } } /** -- cgit v1.2.3