Update to Drupal 8.1.8. For more information, see https://www.drupal.org/project/drupal/releases/8.1.8
This commit is contained in:
parent
e9f047ccf8
commit
f9f23cdf38
312 changed files with 6751 additions and 1546 deletions
|
@ -35,6 +35,21 @@ class RequestHandler implements ContainerAwareInterface {
|
|||
$plugin = $route_match->getRouteObject()->getDefault('_plugin');
|
||||
$method = strtolower($request->getMethod());
|
||||
|
||||
// Symfony is built to transparently map HEAD requests to a GET request. In
|
||||
// the case of the REST module's RequestHandler though, we essentially have
|
||||
// our own light-weight routing system on top of the Drupal/symfony routing
|
||||
// system. So, we have to do the same as what the UrlMatcher does: map HEAD
|
||||
// requests to the logic for GET. This also guarantees response headers for
|
||||
// HEAD requests are identical to those for GET requests, because we just
|
||||
// return a GET response. Response::prepare() will transform it to a HEAD
|
||||
// response at the very last moment.
|
||||
// @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
|
||||
// @see \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection()
|
||||
// @see \Symfony\Component\HttpFoundation\Response::prepare()
|
||||
if ($method === 'head') {
|
||||
$method = 'get';
|
||||
}
|
||||
|
||||
$resource = $this->container
|
||||
->get('plugin.manager.rest')
|
||||
->getInstance(array('id' => $plugin));
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Drupal\rest\Tests;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Tests page caching for REST GET requests.
|
||||
*
|
||||
|
@ -14,7 +17,7 @@ class PageCacheTest extends RESTTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('hal', 'rest', 'entity_test');
|
||||
public static $modules = array('hal');
|
||||
|
||||
/**
|
||||
* Tests that configuration changes also clear the page cache.
|
||||
|
@ -57,4 +60,31 @@ class PageCacheTest extends RESTTestBase {
|
|||
$this->assertCacheTag('entity_test_access:field_test_text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests HEAD support when a REST resource supports GET.
|
||||
*/
|
||||
public function testHeadSupport() {
|
||||
user_role_grant_permissions('anonymous', ['view test entity', 'restful get entity:entity_test']);
|
||||
|
||||
// Create an entity programatically.
|
||||
$this->entityCreate('entity_test')->save();
|
||||
|
||||
$url = Url::fromUri('internal:/entity_test/1?_format=' . $this->defaultFormat);
|
||||
|
||||
$this->enableService('entity:entity_test', 'GET');
|
||||
|
||||
$this->httpRequest($url, 'HEAD', NULL, $this->defaultMimeType);
|
||||
$this->assertResponse(200, 'HTTP response code is correct.');
|
||||
$this->assertHeader('X-Drupal-Cache', 'MISS');
|
||||
$this->assertResponseBody('');
|
||||
|
||||
$response = $this->httpRequest($url, 'GET', NULL, $this->defaultMimeType);
|
||||
$this->assertResponse(200, 'HTTP response code is correct.');
|
||||
$this->assertHeader('X-Drupal-Cache', 'HIT');
|
||||
$this->assertCacheTag('config:rest.settings');
|
||||
$this->assertCacheTag('entity_test:1');
|
||||
$data = Json::decode($response);
|
||||
$this->assertEqual($data['type'][0]['value'], 'entity_test');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,9 +38,28 @@ class ReadTest extends RESTTestBase {
|
|||
// Create an entity programmatically.
|
||||
$entity = $this->entityCreate($entity_type);
|
||||
$entity->save();
|
||||
|
||||
// Verify that it exists: use a HEAD request.
|
||||
$response = $this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'HEAD');
|
||||
$this->assertResponseBody('');
|
||||
$head_headers = $this->drupalGetHeaders();
|
||||
|
||||
// Read it over the REST API.
|
||||
$response = $this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET');
|
||||
$get_headers = $this->drupalGetHeaders();
|
||||
$this->assertResponse('200', 'HTTP response code is correct.');
|
||||
|
||||
// Verify that the GET and HEAD responses are the same, that the only
|
||||
// difference is that there's no body.
|
||||
unset($get_headers['date']);
|
||||
unset($head_headers['date']);
|
||||
unset($get_headers['content-length']);
|
||||
unset($head_headers['content-length']);
|
||||
unset($get_headers['x-drupal-dynamic-cache']);
|
||||
unset($head_headers['x-drupal-dynamic-cache']);
|
||||
$this->assertIdentical($get_headers, $head_headers);
|
||||
$this->assertResponse('200', 'HTTP response code is correct.');
|
||||
|
||||
$this->assertHeader('content-type', $this->defaultMimeType);
|
||||
$data = Json::decode($response);
|
||||
// Only assert one example property here, other properties should be
|
||||
|
|
Reference in a new issue