Merge pull request #8268 from challgren/issue-8267+6051

Read content type in a more compatible way.
This commit is contained in:
Mark Story 2016-02-15 23:32:24 -05:00
commit 337b95a4f5
2 changed files with 29 additions and 1 deletions

View file

@ -165,7 +165,7 @@ class CakeRequest implements ArrayAccess {
if ($_POST) {
$this->data = $_POST;
} elseif (($this->is('put') || $this->is('delete')) &&
strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0
strpos($this->contentType(), 'application/x-www-form-urlencoded') === 0
) {
$data = $this->_readInput();
parse_str($data, $this->data);
@ -394,6 +394,19 @@ class CakeRequest implements ArrayAccess {
}
}
/**
* Get the content type used in this request.
*
* @return string
*/
public function contentType() {
$type = env('CONTENT_TYPE');
if ($type) {
return $type;
}
return env('HTTP_CONTENT_TYPE');
}
/**
* Get the IP the client is using, or says they are using.
*

View file

@ -146,6 +146,21 @@ class CakeRequestTest extends CakeTestCase {
$this->assertFalse(isset($request->query['one']));
}
/**
* Test the content type method.
*
* @return void
*/
public function testContentType() {
$_SERVER['HTTP_CONTENT_TYPE'] = 'application/json';
$request = new CakeRequest('/', false);
$this->assertEquals('application/json', $request->contentType());
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$request = new CakeRequest('/', false);
$this->assertEquals('application/xml', $request->contentType(), 'prefer non http header.');
}
/**
* Test construction
*