Router: allow HEAD method to be defined first
This commit is contained in:
parent
adeab151ba
commit
52e2821597
@ -307,7 +307,7 @@ EOF;
|
||||
if (in_array('GET', $methods)) {
|
||||
// Since we treat HEAD requests like GET requests we don't need to match it.
|
||||
$methodVariable = 'canonicalMethod';
|
||||
$methods = array_filter($methods, function ($method) { return 'HEAD' !== $method; });
|
||||
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
|
||||
}
|
||||
|
||||
if (1 === count($methods)) {
|
||||
|
@ -57,6 +57,17 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
||||
}
|
||||
not_head_and_get:
|
||||
|
||||
// get_and_head
|
||||
if ('/get_and_head' === $pathinfo) {
|
||||
if ('GET' !== $canonicalMethod) {
|
||||
$allow[] = 'GET';
|
||||
goto not_get_and_head;
|
||||
}
|
||||
|
||||
return array('_route' => 'get_and_head');
|
||||
}
|
||||
not_get_and_head:
|
||||
|
||||
// post_and_head
|
||||
if ('/post_and_get' === $pathinfo) {
|
||||
if (!in_array($requestMethod, array('POST', 'HEAD'))) {
|
||||
|
@ -297,6 +297,15 @@ class PhpMatcherDumperTest extends TestCase
|
||||
array(),
|
||||
'',
|
||||
array(),
|
||||
array('HEAD', 'GET')
|
||||
));
|
||||
$headMatchCasesCollection->add('get_and_head', new Route(
|
||||
'/get_and_head',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
array(),
|
||||
array('GET', 'HEAD')
|
||||
));
|
||||
$headMatchCasesCollection->add('post_and_head', new Route(
|
||||
|
Reference in New Issue
Block a user