Skip to content

Commit

Permalink
Provide access to content-* headers via header()
Browse files Browse the repository at this point in the history
The content-* headers are not prefixed with HTTP_ like most other
headers.

Refs #9027
  • Loading branch information
markstory committed Jul 6, 2016
1 parent 446ddf7 commit 67ad9be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Network/Request.php
Expand Up @@ -893,7 +893,10 @@ public function here($base = true)
*/
public function header($name)
{
$name = 'HTTP_' . str_replace('-', '_', $name);
$name = str_replace('-', '_', $name);
if (strtoupper(substr($name, 0, 8)) !== 'CONTENT_') {
$name = 'HTTP_' . $name;
}
return $this->env($name);
}

Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase/Network/RequestTest.php
Expand Up @@ -1038,11 +1038,15 @@ public function testHeader()
{
$request = new Request(['environment' => [
'HTTP_HOST' => 'localhost',
'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'
'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,
]]);

$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'));
}

/**
Expand Down

0 comments on commit 67ad9be

Please sign in to comment.