From cc4b00347c9ff061488bc88194002be701f4190f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 29 Nov 2012 17:21:43 +0200 Subject: Added CI_Output::get_header() (an improved version of PR #645) Also fixed get_content_type() to only return the MIME value and created Output library unit tests for both of these methods. --- system/core/Output.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index 6312ccd86..7bfde07c7 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -256,7 +256,7 @@ class CI_Output { { for ($i = 0, $c = count($this->headers); $i < $c; $i++) { - if (sscanf($this->headers[$i][0], 'Content-Type: %s', $content_type) === 1) + if (sscanf($this->headers[$i][0], 'Content-Type: %[^;]', $content_type) === 1) { return $content_type; } @@ -267,6 +267,39 @@ class CI_Output { // -------------------------------------------------------------------- + /** + * Get Header + * + * @param string $header_name + * @return string + */ + public function get_header($header) + { + // Combine headers already sent with our batched headers + $headers = array_merge( + // We only need [x][0] from our multi-dimensional array + array_map('array_shift', $this->headers), + headers_list() + ); + + if (empty($headers) OR empty($header)) + { + return NULL; + } + + for ($i = 0, $c = count($headers); $i < $c; $i++) + { + if (strncasecmp($header, $headers[$i], $l = strlen($header)) === 0) + { + return trim(substr($headers[$i], $l+1)); + } + } + + return NULL; + } + + // -------------------------------------------------------------------- + /** * Set HTTP Status Header * -- cgit v1.2.3-24-g4f1b