Skip to content

Commit

Permalink
Don't break access to content-md5 header.
Browse files Browse the repository at this point in the history
Also remove some duplicated code in RequestHandlerComponent.
  • Loading branch information
markstory committed Jul 6, 2016
1 parent 3ff051f commit 3d5b0b2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Request.php
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 3d5b0b2

Please sign in to comment.