Skip to content

Commit

Permalink
Adds content headers on POST request in Zend_Controller_Request_HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
froschdesign authored and Dimitris Giotas committed Jun 17, 2016
1 parent 651486e commit 339809b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions library/Zend/Controller/Request/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Zend/Controller/Request/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 339809b

Please sign in to comment.