From 826990fc88208103142385f1a448bb4771213155 Mon Sep 17 00:00:00 2001 From: CJ Date: Tue, 16 Apr 2013 14:17:53 +0800 Subject: apache_request_headers need not go through recapitalization of incoming headers and should be pass through as is. This is a follow up on #2107 (c82b57b) by @danhunsaker; --- system/core/Input.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 6690b7f2e..31bd7008b 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -793,7 +793,7 @@ class CI_Input { // In Apache, you can simply call apache_request_headers() if (function_exists('apache_request_headers')) { - $headers = apache_request_headers(); + $this->headers = apache_request_headers(); } else { @@ -806,15 +806,15 @@ class CI_Input { $headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean); } } - } - // take SOME_HEADER and turn it into Some-Header - foreach ($headers as $key => $val) - { - $key = str_replace(array('_', '-'), ' ', strtolower($key)); - $key = str_replace(' ', '-', ucwords($key)); + // take SOME_HEADER and turn it into Some-Header + foreach ($headers as $key => $val) + { + $key = str_replace('_', ' ', strtolower($key)); + $key = str_replace(' ', '-', ucwords($key)); - $this->headers[$key] = $val; + $this->headers[$key] = $val; + } } return $this->headers; -- cgit v1.2.3-24-g4f1b From 71cff1da396ba0c56644c04fdd2729db6766c557 Mon Sep 17 00:00:00 2001 From: CJ Date: Tue, 16 Apr 2013 21:50:55 +0800 Subject: #2409: Updated based on feedback by @narfbg; --- system/core/Input.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 31bd7008b..7a6b6e4e0 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -790,10 +790,16 @@ class CI_Input { */ public function request_headers($xss_clean = FALSE) { + // If header is already defined, return it immediately + if ( ! empty($this->headers)) + { + return $this->headers; + } + // In Apache, you can simply call apache_request_headers() if (function_exists('apache_request_headers')) { - $this->headers = apache_request_headers(); + return $this->headers = apache_request_headers(); } else { @@ -810,7 +816,7 @@ class CI_Input { // take SOME_HEADER and turn it into Some-Header foreach ($headers as $key => $val) { - $key = str_replace('_', ' ', strtolower($key)); + $key = str_replace(array('_', '-'), ' ', strtolower($key)); $key = str_replace(' ', '-', ucwords($key)); $this->headers[$key] = $val; -- cgit v1.2.3-24-g4f1b From d08e18cafb31af586002e4de39f12cf8e048383b Mon Sep 17 00:00:00 2001 From: CJ Date: Wed, 17 Apr 2013 00:55:48 +0800 Subject: See #2409: Remove double replacing of dashes and instead change `Content-Type` to `CONTENT_TYPE` --- system/core/Input.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 7a6b6e4e0..a0c5552f6 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -803,7 +803,7 @@ class CI_Input { } else { - $headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); + $headers['CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); foreach ($_SERVER as $key => $val) { @@ -816,7 +816,7 @@ class CI_Input { // take SOME_HEADER and turn it into Some-Header foreach ($headers as $key => $val) { - $key = str_replace(array('_', '-'), ' ', strtolower($key)); + $key = str_replace('_', ' ', strtolower($key)); $key = str_replace(' ', '-', ucwords($key)); $this->headers[$key] = $val; -- cgit v1.2.3-24-g4f1b From d195f224db31644eaaef4b4cb4713d9af5f57ead Mon Sep 17 00:00:00 2001 From: CJ Date: Wed, 17 Apr 2013 01:04:13 +0800 Subject: See #2409: Reformating and code cleanup for request_headers; --- system/core/Input.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index a0c5552f6..6b7d5bd43 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -801,25 +801,18 @@ class CI_Input { { return $this->headers = apache_request_headers(); } - else - { - $headers['CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); - foreach ($_SERVER as $key => $val) - { - if (sscanf($key, 'HTTP_%s', $header) === 1) - { - $headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean); - } - } + $this->headers['CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); - // take SOME_HEADER and turn it into Some-Header - foreach ($headers as $key => $val) + foreach ($_SERVER as $key => $val) + { + if (sscanf($key, 'HTTP_%s', $header) === 1) { - $key = str_replace('_', ' ', strtolower($key)); - $key = str_replace(' ', '-', ucwords($key)); + // take SOME_HEADER and turn it into Some-Header + $header = str_replace('_', ' ', strtolower($header)); + $header = str_replace(' ', '-', ucwords($header)); - $this->headers[$key] = $val; + $this->headers[$header] = $this->_fetch_from_array($_SERVER, $key, $xss_clean); } } -- cgit v1.2.3-24-g4f1b From c5c522a069cc504509955890aacd55b97979043b Mon Sep 17 00:00:00 2001 From: CJ Date: Wed, 17 Apr 2013 11:59:22 +0800 Subject: #2409: Force Content Type to go through camelization; --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 6b7d5bd43..ff0bbe060 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -802,7 +802,7 @@ class CI_Input { return $this->headers = apache_request_headers(); } - $this->headers['CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); + $_SERVER['HTTP_CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); foreach ($_SERVER as $key => $val) { -- cgit v1.2.3-24-g4f1b From 8347f9161a1ba080be62b22eb546cceea8f8a8e9 Mon Sep 17 00:00:00 2001 From: CJ Date: Wed, 17 Apr 2013 21:45:22 +0800 Subject: See #2409: Avoid overwriting global $_SERVER and set Content-Type to protected property; --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index ff0bbe060..0ef81128e 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -802,7 +802,7 @@ class CI_Input { return $this->headers = apache_request_headers(); } - $_SERVER['HTTP_CONTENT_TYPE'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); + $this->headers['Content-Type'] = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : @getenv('CONTENT_TYPE'); foreach ($_SERVER as $key => $val) { -- cgit v1.2.3-24-g4f1b