diff --git a/core/modules/rest/config/install/rest.settings.yml b/core/modules/rest/config/install/rest.settings.yml index e2699fc..a3c8d25 100644 --- a/core/modules/rest/config/install/rest.settings.yml +++ b/core/modules/rest/config/install/rest.settings.yml @@ -25,6 +25,11 @@ resources: - hal_json supported_auth: - basic_auth + OPTIONS: + supported_formats: + - hal_json + supported_auth: + - basic_auth # Multiple formats and multiple authentication providers can be defined for a # resource: diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 718f5c8..5bfaa7e 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -192,6 +192,21 @@ public function delete(EntityInterface $entity) { } /** + * Responds to entity OPTIONS requests. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity object. + * + * @return \Drupal\rest\ResourceResponse + * The HTTP response object. + * + * @throws \Symfony\Component\HttpKernel\Exception\HttpException + */ + public function options(EntityInterface $entity) { + return new ResourceResponse(NULL, 204); + } + + /** * Verifies that the whole entity does not violate any validation constraints. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/core/modules/rest/src/Routing/OptionsRequestSubscriber.php b/core/modules/rest/src/Routing/OptionsRequestSubscriber.php index 4539247..3f26345 100644 --- a/core/modules/rest/src/Routing/OptionsRequestSubscriber.php +++ b/core/modules/rest/src/Routing/OptionsRequestSubscriber.php @@ -71,6 +71,7 @@ public function onKernelRequest(GetResponseEvent $event) { $allowed_methods = implode(' ', $this->getAllowedMethods($request)); $response = new Response(NULL, 200, array('Allow' => $allowed_methods)); $event->setResponse($response); + $event->stopPropagation(); } } diff --git a/core/modules/rest/tests/src/Routing/OptionsRequestSubscriberTest.php b/core/modules/rest/tests/src/Routing/OptionsRequestSubscriberTest.php deleted file mode 100644 index 50115a9..0000000 --- a/core/modules/rest/tests/src/Routing/OptionsRequestSubscriberTest.php +++ /dev/null @@ -1,27 +0,0 @@ - 'Options request subscriber tests', - 'description' => 'Tests that OPTIONS requests work correctly.', - 'group' => 'REST', - ); - } -}