mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Merge pull request #8268 from challgren/issue-8267+6051
Read content type in a more compatible way.
This commit is contained in:
commit
337b95a4f5
2 changed files with 29 additions and 1 deletions
|
@ -165,7 +165,7 @@ class CakeRequest implements ArrayAccess {
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
$this->data = $_POST;
|
$this->data = $_POST;
|
||||||
} elseif (($this->is('put') || $this->is('delete')) &&
|
} 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();
|
$data = $this->_readInput();
|
||||||
parse_str($data, $this->data);
|
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.
|
* Get the IP the client is using, or says they are using.
|
||||||
*
|
*
|
||||||
|
|
|
@ -146,6 +146,21 @@ class CakeRequestTest extends CakeTestCase {
|
||||||
$this->assertFalse(isset($request->query['one']));
|
$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
|
* Test construction
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue