Merge pull request #8844 from icyrizard/add_http_patch_content_type_check

Add HTTP patch Content-Type check
This commit is contained in:
Mark Story 2016-05-27 15:41:18 +02:00
commit 55e9638044
3 changed files with 10 additions and 1 deletions

View file

@ -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)) {

View file

@ -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'),

View file

@ -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';