diff --git a/library/Zend/Controller/Request/Http.php b/library/Zend/Controller/Request/Http.php index ba53a06f37..cabcca764c 100644 --- a/library/Zend/Controller/Request/Http.php +++ b/library/Zend/Controller/Request/Http.php @@ -986,8 +986,18 @@ public function getHeader($header) } // Try to get it from the $_SERVER array first - $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header)); - if (isset($_SERVER[$temp])) { + $temp = strtoupper(str_replace('-', '_', $header)); + if (isset($_SERVER['HTTP_' . $temp])) { + return $_SERVER['HTTP_' . $temp]; + } + + /* + * Try to get it from the $_SERVER array on POST request or CGI environment + * @see https://www.ietf.org/rfc/rfc3875 (4.1.2. and 4.1.3.) + */ + if (isset($_SERVER[$temp]) + && in_array($temp, array('CONTENT_TYPE', 'CONTENT_LENGTH')) + ) { return $_SERVER[$temp]; } diff --git a/tests/Zend/Controller/Request/HttpTest.php b/tests/Zend/Controller/Request/HttpTest.php index 2a17a7825f..f2d54f008c 100644 --- a/tests/Zend/Controller/Request/HttpTest.php +++ b/tests/Zend/Controller/Request/HttpTest.php @@ -660,6 +660,22 @@ public function testGetHeader() $this->assertFalse($this->_request->getHeader('X-No-Such-Thing')); } + /** + * @see https://www.ietf.org/rfc/rfc3875 (4.1.2. and 4.1.3.) + */ + public function testGetContentHeadersOnPostRequest() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_SERVER['CONTENT_LENGTH'] = 100; + $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + + $this->assertEquals(100, $this->_request->getHeader('Content-Length')); + $this->assertEquals( + 'application/x-www-form-urlencoded', + $this->_request->getHeader('Content-Type') + ); + } + public function testGetHeaderThrowsExceptionWithNoInput() { try {