summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-29 16:21:43 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-29 16:21:43 +0100
commitcc4b00347c9ff061488bc88194002be701f4190f (patch)
tree899984be1b01268cff965aa30d31e5f56a8701a3 /system
parente1d6c46b7d5e3d82dc6953af29f0b02ccb03e2dc (diff)
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.
Diffstat (limited to 'system')
-rw-r--r--system/core/Output.php35
1 files changed, 34 insertions, 1 deletions
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;
}
@@ -268,6 +268,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
*
* As of version 1.7.2, this is an alias for common function