diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php index bec2bd1..694a422 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php @@ -60,7 +60,7 @@ class RestExport extends PathPluginBase { * * @var string */ - protected $contentType; + protected $contentType = 'json'; /** * The mime type for the response. @@ -79,7 +79,14 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio $negotiation = $container->get('content_negotiation'); $request = $container->get('request'); - $this->setContentType($negotiation->getContentType($request)); + $request_content_type = $negotiation->getContentType($request); + // Only use the requested content type if it's not 'html'. If it is then + // default to 'json' to aid debugging. + // @todo Remove the need for this when we have better content negotiation. + if ($request_content_type != 'html') { + $this->setContentType($request_content_type); + } + $this->setMimeType($request->getMimeType($this->contentType)); } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php index ecf81f6..ccec21c 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/Views/StyleSerializerTest.php @@ -151,6 +151,15 @@ public function testReponseFormatConfiguration() { $this->drupalPost(NULL, array(), t('Save')); // Should return a 200. + // @todo This should be fixed when we have better content negotiation. + $this->drupalGet('test/serialize/field', array(), array('Accept: */*')); + $this->assertResponse(200, 'A 200 response was returned when HTML was requested.'); + + // Should return a 200. Emulates a sample firefow header. + $this->drupalGet('test/serialize/field', array(), array('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')); + $this->assertResponse(200, 'A 200 response was returned when HTML was requested.'); + + // Should return a 200. $this->drupalGet('test/serialize/field', array(), array('Accept: application/json')); $this->assertResponse(200, 'A 200 response was returned when JSON was requested.'); // Should return a 200.