Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit f7393dc

Browse files
committed
Adds content headers on POST request in Zend_Controller_Request_HTTP
Closes zendframework#477
1 parent 7aecbff commit f7393dc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

library/Zend/Controller/Request/Http.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,18 @@ public function getHeader($header)
986986
}
987987

988988
// Try to get it from the $_SERVER array first
989-
$temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header));
990-
if (isset($_SERVER[$temp])) {
989+
$temp = strtoupper(str_replace('-', '_', $header));
990+
if (isset($_SERVER['HTTP_' . $temp])) {
991+
return $_SERVER['HTTP_' . $temp];
992+
}
993+
994+
/*
995+
* Try to get it from the $_SERVER array on POST request or CGI environment
996+
* @see https://www.ietf.org/rfc/rfc3875 (4.1.2. and 4.1.3.)
997+
*/
998+
if (isset($_SERVER[$temp])
999+
&& in_array($temp, array('CONTENT_TYPE', 'CONTENT_LENGTH'))
1000+
) {
9911001
return $_SERVER[$temp];
9921002
}
9931003

tests/Zend/Controller/Request/HttpTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,22 @@ public function testGetHeader()
660660
$this->assertFalse($this->_request->getHeader('X-No-Such-Thing'));
661661
}
662662

663+
/**
664+
* @see https://www.ietf.org/rfc/rfc3875 (4.1.2. and 4.1.3.)
665+
*/
666+
public function testGetContentHeadersOnPostRequest()
667+
{
668+
$_SERVER['REQUEST_METHOD'] = 'POST';
669+
$_SERVER['CONTENT_LENGTH'] = 100;
670+
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
671+
672+
$this->assertEquals(100, $this->_request->getHeader('Content-Length'));
673+
$this->assertEquals(
674+
'application/x-www-form-urlencoded',
675+
$this->_request->getHeader('Content-Type')
676+
);
677+
}
678+
663679
public function testGetHeaderThrowsExceptionWithNoInput()
664680
{
665681
try {

0 commit comments

Comments
 (0)