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/THttpResponse.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'framework/Web/THttpResponse.php') diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index 1f314dda..9ef55b76 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -476,10 +476,10 @@ class THttpResponse extends TModule implements ITextWriter { Prado::trace("Flushing output",'System.Web.THttpResponse'); $this->ensureHeadersSent(); - if($this->_bufferOutput) + if($this->_bufferOutput) { // avoid forced send of http headers (ob_flush() does that) if there's no output yet - if (ob_get_length()>0) + if (ob_get_length()>0) { if (!$continueBuffering) { @@ -568,6 +568,30 @@ class THttpResponse extends TModule implements ITextWriter Prado::trace("Clearing output",'System.Web.THttpResponse'); } + /** + * @param integer|null Either {@link CASE_UPPER} or {@link CASE_LOWER} or as is null (default) + * @return array + */ + public function getHeaders($case=null) + { + $result = array(); + $headers = headers_list(); + foreach($headers as $header) { + $tmp = explode(':', $header); + $key = trim(array_shift($tmp)); + $value = trim(implode(':', $tmp)); + if(isset($result[$key])) + $result[$key] .= ', ' . $value; + else + $result[$key] = $value; + } + + if($case !== null) + return array_change_key_case($result, $case); + + return $result; + } + /** * Sends a header. * @param string header @@ -673,7 +697,7 @@ class THttpResponse extends TModule implements ITextWriter if($this->getHasAdapter()) return $this->_adapter->createNewHtmlWriter($type, $this); else - return $this->createNewHtmlWriter($type, $this); + return $this->createNewHtmlWriter($type, $this); } /** -- cgit v1.2.3