diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/DBLogResource.php b/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/DBLogResource.php index 7ec6b3e..5a1fe31 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/DBLogResource.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/DBLogResource.php @@ -47,11 +47,6 @@ public function routes() { */ public function get($id = NULL) { if ($id) { - $result = db_select('watchdog', 'w') - ->condition('wid', $id) - ->fields('w') - ->execute() - ->fetchAll(); $result = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", array(':wid' => $id)) ->fetchObject(); if (!empty($result)) { diff --git a/core/modules/rest/lib/Drupal/rest/RequestHandler.php b/core/modules/rest/lib/Drupal/rest/RequestHandler.php index a45ebf8..a374d14 100644 --- a/core/modules/rest/lib/Drupal/rest/RequestHandler.php +++ b/core/modules/rest/lib/Drupal/rest/RequestHandler.php @@ -55,7 +55,7 @@ public function handle($plugin, Request $request, $id = NULL) { // Accept headers. See http://drupal.org/node/1833440 $output = $serializer->serialize($data, 'drupal_jsonld'); $response->setContent($output); - $response->headers->set('Content-Type', 'application/ld+json'); + $response->headers->set('Content-Type', 'application/vnd.drupal.ld+json'); } return $response; } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/DBLogTest.php b/core/modules/rest/lib/Drupal/rest/Tests/DBLogTest.php index 44922c7..5002397 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/DBLogTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/DBLogTest.php @@ -50,15 +50,16 @@ public function testWatchdog() { $account = $this->drupalCreateUser(array('restful get dblog')); $this->drupalLogin($account); - $response = $this->httpRequest("dblog/$id", 'GET'); + $response = $this->httpRequest("dblog/$id", 'GET', NULL, 'application/json'); $this->assertResponse(200); + $this->assertHeader('Content-Type', 'application/json'); $log = drupal_json_decode($response); $this->assertEqual($log['wid'], $id, 'Log ID is correct.'); $this->assertEqual($log['type'], 'rest_test', 'Type of log message is correct.'); $this->assertEqual($log['message'], 'Test message', 'Log message text is correct.'); // Request an unknown log entry. - $response = $this->httpRequest("dblog/9999", 'GET'); + $response = $this->httpRequest("dblog/9999", 'GET', NULL, 'application/json'); $this->assertResponse(404); $this->assertEqual($response, 'Not Found', 'Response message is correct.'); } diff --git a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php index eed04fb..acf4802 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php @@ -15,6 +15,13 @@ abstract class RESTTestBase extends WebTestBase { /** + * Stores HTTP response headers from the last HTTP request. + * + * @var array + */ + protected $responseHeaders; + + /** * Helper function to issue a HTTP request with simpletest's cURL. * * @param string $url @@ -31,47 +38,62 @@ protected function httpRequest($url, $method, $body = NULL, $format = 'applicati case 'GET': // Set query if there are additional GET parameters. $options = isset($body) ? array('absolute' => TRUE, 'query' => $body) : array('absolute' => TRUE); - $response = $this->curlExec(array( + $curl_options = array( CURLOPT_HTTPGET => TRUE, CURLOPT_URL => url($url, $options), - CURLOPT_NOBODY => FALSE) + CURLOPT_NOBODY => FALSE ); break; + case 'POST': - $response = $this->curlExec(array( + $curl_options = array( CURLOPT_HTTPGET => FALSE, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $body, CURLOPT_URL => url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('Content-Type: ' . $format), - )); + ); break; + case 'PUT': - $response = $this->curlExec(array( + $curl_options = array( CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $body, CURLOPT_URL => url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, CURLOPT_HTTPHEADER => array('Content-Type: ' . $format), - )); + ); break; + case 'DELETE': - $response = $this->curlExec(array( + $curl_options = array( CURLOPT_HTTPGET => FALSE, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_URL => url($url, array('absolute' => TRUE)), CURLOPT_NOBODY => FALSE, - )); + ); break; } + // Include all HTTP headers in the response. + $curl_options[CURLOPT_HEADER] = TRUE; + + $response = $this->curlExec($curl_options); + + list($header, $body) = explode("\r\n\r\n", $response, 2); + $header_lines = explode("\r\n", $header); + foreach ($header_lines as $line) { + $parts = explode(':', $line, 2); + $this->responseHeaders[$parts[0]] = isset($parts[1]) ? trim($parts[1]) : ''; + } $this->verbose($method . ' request to: ' . $url . '