core/lib/Drupal/Core/Routing/MethodFilter.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Routing/MethodFilter.php b/core/lib/Drupal/Core/Routing/MethodFilter.php index 77c9fa5..e565a3e 100644 --- a/core/lib/Drupal/Core/Routing/MethodFilter.php +++ b/core/lib/Drupal/Core/Routing/MethodFilter.php @@ -22,11 +22,6 @@ public function filter(RouteCollection $collection, Request $request) { foreach ($collection->all() as $name => $route) { $supported_methods = $route->getMethods(); - // If the GET method is allowed we also need to allow the HEAD method - // since HEAD is a GET method that doesn't return the body. - if (in_array('GET', $supported_methods)) { - $supported_methods[] = 'HEAD'; - } // A route not restricted to specific methods allows any method. If this // is the case, we'll also have at least one route left in the collection, @@ -34,7 +29,14 @@ public function filter(RouteCollection $collection, Request $request) { if (empty($supported_methods)) { continue; } - elseif (!in_array($method, $supported_methods)) { + + // If the GET method is allowed we also need to allow the HEAD method + // since HEAD is a GET method that doesn't return the body. + if (in_array('GET', $supported_methods, TRUE)) { + $supported_methods[] = 'HEAD'; + } + + if (!in_array($method, $supported_methods, TRUE)) { $all_supported_methods = array_merge($supported_methods, $all_supported_methods); $collection->remove($name); }