8000 Router: allow HEAD method to be defined first · symfony/symfony@52e2821 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52e2821

Browse files
committed
Router: allow HEAD method to be defined first
1 parent adeab15 commit 52e2821

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
307307
if (in_array('GET', $methods)) {
308308
// Since we treat HEAD requests like GET requests we don't need to match it.
309309
$methodVariable = 'canonicalMethod';
310-
$methods = array_filter($methods, function ($method) { return 'HEAD' !== $method; });
310+
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
311311
}
312312

313313
if (1 === count($methods)) {

src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public function match($pathinfo)
5757
}
5858
not_head_and_get:
5959

60+
// get_and_head
61+
if ('/get_and_head' === $pathinfo) {
62+
if ('GET' !== $canonicalMethod) {
63+
$allow[] = 'GET';
64+
goto not_get_and_head;
65+
}
66+
67+
return array('_route' => 'get_and_head');
68+
}
69+
not_get_and_head:
70+
6071
// post_and_head
6172
if ('/post_and_get' === $pathinfo) {
6273
if (!in_array($requestMethod, array('POST', 'HEAD'))) {

src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ public function getRouteCollections()
297297
array(),
298298
'',
299299
array(),
300+
array('HEAD', 'GET')
301+
));
302+
$headMatchCasesCollection->add('get_and_head', new Route(
303+
'/get_and_head',
304+
array(),
305+
array(),
306+
array(),
307+
'',
308+
array(),
300309
array('GET', 'HEAD')
301310
));
302311
$headMatchCasesCollection->add('post_and_head', new Route(

0 commit comments

Comments
 (0)
0