mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #8844 from icyrizard/add_http_patch_content_type_check
Add HTTP patch Content-Type check
This commit is contained in:
commit
55e9638044
3 changed files with 10 additions and 1 deletions
|
@ -505,7 +505,12 @@ class RequestHandlerComponent extends Component {
|
|||
* in the request content type will be returned.
|
||||
*/
|
||||
public function requestedWith($type = null) {
|
||||
if (!$this->request->is('post') && !$this->request->is('put') && !$this->request->is('delete')) {
|
||||
if (
|
||||
!$this->request->is('patch') &&
|
||||
!$this->request->is('post') &&
|
||||
!$this->request->is('put') &&
|
||||
!$this->request->is('delete')
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
if (is_array($type)) {
|
||||
|
|
|
@ -97,6 +97,7 @@ class CakeRequest implements ArrayAccess {
|
|||
*/
|
||||
protected $_detectors = array(
|
||||
'get' => array('env' => 'REQUEST_METHOD', 'value' => 'GET'),
|
||||
'patch' => array('env' => 'REQUEST_METHOD', 'value' => 'PATCH'),
|
||||
'post' => array('env' => 'REQUEST_METHOD', 'value' => 'POST'),
|
||||
'put' => array('env' => 'REQUEST_METHOD', 'value' => 'PUT'),
|
||||
'delete' => array('env' => 'REQUEST_METHOD', 'value' => 'DELETE'),
|
||||
|
|
|
@ -618,6 +618,9 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
|||
$_SERVER['REQUEST_METHOD'] = 'DELETE';
|
||||
$this->assertEquals('json', $this->RequestHandler->requestedWith());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'PATCH';
|
||||
$this->assertEquals('json', $this->RequestHandler->requestedWith());
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
unset($_SERVER['CONTENT_TYPE']);
|
||||
$_SERVER['HTTP_CONTENT_TYPE'] = 'application/json';
|
||||
|
|
Loading…
Reference in a new issue