Jelajahi Sumber

Merge branch 'froschdesign-hotfix/477'

Rob Allen 11 tahun lalu
induk
melakukan
7681ab86f4

+ 12 - 2
library/Zend/Controller/Request/Http.php

@@ -986,8 +986,18 @@ class Zend_Controller_Request_Http extends Zend_Controller_Request_Abstract
         }
 
         // 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];
         }
 

+ 16 - 0
tests/Zend/Controller/Request/HttpTest.php

@@ -660,6 +660,22 @@ class Zend_Controller_Request_HttpTest extends PHPUnit_Framework_TestCase
         $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 {