Commit 76ecf77f authored by alexpott's avatar alexpott

Issue #2537602 by hchonov, dawehner: JQuery ajax GET requests result in "406 Not Acceptable"

parent 9fb5187d
......@@ -37,10 +37,6 @@ public function getContentType(Request $request) {
return $request->query->get('_format');
}
if ($request->isXmlHttpRequest()) {
return 'ajax';
}
// Do HTML last so that it always wins.
return 'html';
}
......
......@@ -1555,7 +1555,15 @@ protected function drupalGetAjax($path, array $options = array(), array $headers
if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) {
$options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax';
}
return Json::decode($this->drupalGet($path, $options, $headers));
return Json::decode($this->drupalGetXHR($path, $options, $headers));
}
/**
* Requests a Drupal path as if it is a XMLHttpRequest.
*/
protected function drupalGetXHR($path, array $options = array(), array $headers = array()) {
$headers[] = 'X-Requested-With: XMLHttpRequest';
return $this->drupalGet($path, $options, $headers);
}
/**
......
......@@ -94,6 +94,10 @@ public function testDialog() {
$this->drupalGet('ajax-test/dialog-contents');
$this->assertRaw($dialog_contents, 'Non-JS modal dialog page present.');
// Check that requesting a modal dialog with XMLHttpRequest goes to a page.
$this->drupalGetXHR('ajax-test/dialog-contents');
$this->assertRaw($dialog_contents, 'Modal dialog page on XMLHttpRequest present.');
// Emulate going to the JS version of the page and check the JSON response.
$ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal')));
$this->assertEqual($modal_expected_response, $ajax_result[3], 'Modal dialog JSON response matches.');
......
......@@ -73,7 +73,7 @@ public function testUnknowContentTypeButAjaxRequest() {
$request = new Request();
$request->headers->set('X-Requested-With', 'XMLHttpRequest');
$this->assertSame('ajax', $this->contentNegotiation->getContentType($request));
$this->assertSame('html', $this->contentNegotiation->getContentType($request));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment