@@ -118,6 +118,10 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
118
118
*/
119
119
protected function matchCollection ($ pathinfo , RouteCollection $ routes )
120
120
{
121
+ // HEAD and GET are equivalent as per RFC
122
+ if ('HEAD ' === $ method = $ this ->context ->getMethod ()) {
123
+ $ method = 'GET ' ;
124
+ }
121
125
$ supportsTrailingSlash = '/ ' !== $ pathinfo && '' !== $ pathinfo && $ this instanceof RedirectableUrlMatcherInterface;
122
126
123
127
foreach ($ routes as $ name => $ route ) {
@@ -128,7 +132,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
128
132
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
129
133
if ('' === $ staticPrefix || 0 === strpos ($ pathinfo , $ staticPrefix )) {
130
134
// no-op
131
- } elseif (!$ supportsTrailingSlash || ($ requiredMethods && !\in_array ('GET ' , $ requiredMethods ))) {
135
+ } elseif (!$ supportsTrailingSlash || ($ requiredMethods && !\in_array ('GET ' , $ requiredMethods )) || ' GET ' !== $ method ) {
132
136
continue ;
133
137
} elseif ('/ ' === substr ($ staticPrefix , -1 ) && substr ($ staticPrefix , 0 , -1 ) === $ pathinfo ) {
134
138
return $ this ->allow = array ();
@@ -149,7 +153,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
149
153
}
150
154
151
155
if ($ hasTrailingSlash && '/ ' !== substr ($ pathinfo , -1 )) {
152
- if (!$ requiredMethods || \in_array ('GET ' , $ requiredMethods )) {
156
+ if (( !$ requiredMethods || \in_array ('GET ' , $ requiredMethods )) && ' GET ' === $ method ) {
153
157
return $ this ->allow = array ();
154
158
}
155
159
continue ;
@@ -168,11 +172,6 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
168
172
169
173
// check HTTP method requirement
170
174
if ($ requiredMethods ) {
171
- // HEAD and GET are equivalent as per RFC
172
- if ('HEAD ' === $ method = $ this ->context ->getMethod ()) {
173
- $ method = 'GET ' ;
174
- }
175
-
176
175
if (!\in_array ($ method , $ requiredMethods )) {
177
176
if (self ::REQUIREMENT_MATCH === $ status [0 ]) {
178
177
$ this ->allow = array_merge ($ this ->allow , $ requiredMethods );
0 commit comments