.../Drupal/Core/Routing/ContentTypeHeaderMatcher.php | 5 +++-- .../Core/Routing/ContentTypeHeaderMatcherTest.php | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php index 16316ea..719eeb1 100644 --- a/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php +++ b/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php @@ -16,8 +16,9 @@ class ContentTypeHeaderMatcher implements FilterInterface { */ public function filter(RouteCollection $collection, Request $request) { // The Content-type header does not make sense on GET requests, because GET - // requests do not carry any content. Nothing to filter in this case. - if ($request->isMethod('GET') || $request->isMethod('HEAD')) { + // requests do not carry any content. Nothing to filter in this case. Same + // for all other safe methods. + if ($request->isMethodSafe(FALSE)) { return $collection; } diff --git a/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php b/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php index 21357a1..87e3f3e 100644 --- a/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/ContentTypeHeaderMatcherTest.php @@ -42,19 +42,26 @@ protected function setUp() { } /** - * Tests that routes are not filtered on GET requests. + * Tests that routes are not filtered on safe requests. + * + * @dataProvider providerTestSafeRequestFilter */ - public function testGetRequestFilter() { + public function testSafeRequestFilter($method) { $collection = $this->fixtures->sampleRouteCollection(); $collection->addCollection($this->fixtures->contentRouteCollection()); - $request = Request::create('path/two', 'GET'); + $request = Request::create('path/two', $method); $routes = $this->matcher->filter($collection, $request); $this->assertEquals(count($routes), 7, 'The correct number of routes was found.'); + } - $request = Request::create('path/two', 'HEAD'); - $routes = $this->matcher->filter($collection, $request); - $this->assertEquals(count($routes), 7, 'The correct number of routes was found.'); + public function providerTestSafeRequestFilter() { + return [ + ['GET'], + ['HEAD'], + ['OPTIONS'], + ['TRACE'], + ]; } /**