diff --git a/src/Controller/Component/RequestHandlerComponent.php b/src/Controller/Component/RequestHandlerComponent.php index d5ac75cdf42..d8c2c346290 100644 --- a/src/Controller/Component/RequestHandlerComponent.php +++ b/src/Controller/Component/RequestHandlerComponent.php @@ -455,10 +455,7 @@ public function requestedWith($type = null) return false; } - list($contentType) = explode(';', $request->env('CONTENT_TYPE')); - if ($contentType === '') { - list($contentType) = explode(';', $request->header('CONTENT_TYPE')); - } + list($contentType) = explode(';', $request->contentType()); $response = $this->response; if ($type === null) { return $response->mapType($contentType); diff --git a/src/Network/Request.php b/src/Network/Request.php index 0ce13f95429..257eed38839 100644 --- a/src/Network/Request.php +++ b/src/Network/Request.php @@ -894,7 +894,7 @@ public function here($base = true) public function header($name) { $name = str_replace('-', '_', $name); - if (strtoupper(substr($name, 0, 8)) !== 'CONTENT_') { + if (!in_array(strtoupper($name), ['CONTENT_LENGTH', 'CONTENT_TYPE'])) { $name = 'HTTP_' . $name; } return $this->env($name); diff --git a/tests/TestCase/Network/RequestTest.php b/tests/TestCase/Network/RequestTest.php index 759f34a0c19..a39b4751c8a 100644 --- a/tests/TestCase/Network/RequestTest.php +++ b/tests/TestCase/Network/RequestTest.php @@ -1041,12 +1041,14 @@ public function testHeader() 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-ca) AppleWebKit/534.8+ (KHTML, like Gecko) Version/5.0 Safari/533.16', 'CONTENT_TYPE' => 'application/json', 'CONTENT_LENGTH' => 1337, + 'HTTP_CONTENT_MD5' => 'abc123' ]]); $this->assertEquals($request->env('HTTP_HOST'), $request->header('host')); $this->assertEquals($request->env('HTTP_USER_AGENT'), $request->header('User-Agent')); $this->assertEquals($request->env('CONTENT_LENGTH'), $request->header('content-length')); $this->assertEquals($request->env('CONTENT_TYPE'), $request->header('content-type')); + $this->assertEquals($request->env('HTTP_CONTENT_MD5'), $request->header('content-md5')); } /**