Skip to content

Commit

Permalink
Fix incorrect type detection when ajax + json are available.
Browse files Browse the repository at this point in the history
Make ajax happen after content-type negotiation so that when jQuery
talks to CakePHP the requests don't get marked as ajax and instead get
marked as json.
  • Loading branch information
markstory committed Aug 23, 2014
1 parent 0ccbfcf commit 8e28b7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -155,12 +155,12 @@ public function initialize(Event $event) {
if (isset($this->request->params['_ext'])) {
$this->ext = $this->request->params['_ext'];
}
if (empty($this->ext) && $this->request->is('ajax')) {
$this->ext = 'ajax';
}
if (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
$this->_setExtension();
}
if (empty($this->ext) && $this->request->is('ajax')) {
$this->ext = 'ajax';
}

$classMap = $this->_config['viewClassMap'];
if ($classMap) {
Expand Down
Expand Up @@ -140,6 +140,7 @@ public function testInitializeContentTypeSettingExt() {
*/
public function testInitializeContentTypeWithjQueryAccept() {
$_SERVER['HTTP_ACCEPT'] = 'application/json, application/javascript, */*; q=0.01';
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$event = new Event('Controller.initialize', $this->Controller);
$this->assertNull($this->RequestHandler->ext);
Router::parseExtensions('json', false);
Expand Down

0 comments on commit 8e28b7c

Please sign in to comment.