From 00adf1d480f94692a625ec2165e0fcc9171c6e2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 12:30:50 +0300 Subject: Some improvements to the additions from pull #1234 --- system/core/Output.php | 14 +++++++------- user_guide_src/source/changelog.rst | 4 ++-- user_guide_src/source/libraries/output.rst | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/system/core/Output.php b/system/core/Output.php index 09d74f0c0..01fd1d867 100755 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -220,24 +220,24 @@ class CI_Output { $this->headers[] = array($header, TRUE); return $this; } - + // -------------------------------------------------------------------- - + /** * Get Current Content Type Header - * Return text/html if Content-Type is not set * - * @return string + * @return string 'text/html', if not already set */ public function get_content_type() { - foreach ($this->headers as $header) + for ($i = 0, $c = count($this->headers); $i < $c; $i++) { - if (preg_match('/^Content-Type/', $header[0])) + if (preg_match('/^Content-Type:\s(.+)$/', $this->headers[$i][0], $matches)) { - return str_replace('Content-Type: ', '', $header[0]); + return $matches[1]; } } + return 'text/html'; } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 770d68a8e..c3e0e1dc0 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -129,8 +129,8 @@ Release Date: Not Released - Added method() to CI_Input to retrieve $_SERVER['REQUEST_METHOD']. - Modified valid_ip() to use PHP's filter_var() in the :doc:`Input Library `. - Added support for HTTP-Only cookies with new config option ``cookie_httponly`` (default FALSE). - - Renamed method _call_hook() to call_hook() in the :doc:`Hooks Library `. - - Added get_content_type for get current mime-types :doc:`Core Output Library `. + - Renamed method _call_hook() to call_hook() in the :doc:`Hooks Library `. + - Added get_content_type() method to the :doc:`Output Library `. Bug fixes for 3.0 ------------------ diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 7fd2a1c72..baceaae7b 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -52,9 +52,11 @@ data, JPEG's, XML, etc easily. $this->output->get_content_type(); ========================================== -Get the current mime-type of your page and return 'text/html' by default. +Returns the Content-Type HTTP header that's currently in use. - $this->output->get_content_type(); + $mime = $this->output->get_content_type(); + +.. note:: If not set, the default return value is 'text/html'. $this->output->get_output(); ============================= -- cgit v1.2.3-24-g4f1b