Skip to content
Permalink
Browse files

Fix incorrect type detection when ajax + json are available.

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 8e28b7c2770b2b8933c8dc176e9cfb82f7527a57
@@ -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) {
@@ -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);

0 comments on commit 8e28b7c

Please sign in to comment.
You can’t perform that action at this time.