@@ -130,6 +130,10 @@ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterfac
130
130
*/
131
131
protected function matchCollection ($ pathinfo , RouteCollection $ routes )
132
132
{
133
+ // HEAD and GET are equivalent as per RFC
134
+ if ('HEAD ' === $ method = $ this ->context ->getMethod ()) {
135
+ $ method = 'GET ' ;
136
+ }
133
137
$ supportsTrailingSlash = '/ ' !== $ pathinfo && '' !== $ pathinfo && $ this instanceof RedirectableUrlMatcherInterface;
134
138
135
139
foreach ($ routes as $ name => $ route ) {
@@ -140,7 +144,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
140
144
// check the static prefix of the URL first. Only use the more expensive preg_match when it matches
141
145
if ('' === $ staticPrefix || 0 === strpos ($ pathinfo , $ staticPrefix )) {
142
146
// no-op
143
- } elseif (!$ supportsTrailingSlash || ($ requiredMethods && !\in_array ('GET ' , $ requiredMethods ))) {
147
+ } elseif (!$ supportsTrailingSlash || ($ requiredMethods && !\in_array ('GET ' , $ requiredMethods )) || ' GET ' !== $ method ) {
144
148
continue ;
145
149
} elseif ('/ ' === $ staticPrefix [-1 ] && substr ($ staticPrefix , 0 , -1 ) === $ pathinfo ) {
146
150
return $ this ->allow = $ this ->allowSchemes = array ();
@@ -170,7 +174,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
170
174
}
171
175
}
172
176
if ($ hasTrailingSlash !== ('/ ' === $ pathinfo [-1 ])) {
173
- if (!$ requiredMethods || \in_array ('GET ' , $ requiredMethods )) {
177
+ if (( !$ requiredMethods || \in_array ('GET ' , $ requiredMethods )) && ' GET ' === $ method ) {
174
178
return $ this ->allow = $ this ->allowSchemes = array ();
175
179
}
176
180
continue ;
@@ -190,11 +194,6 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
190
194
191
195
$ hasRequiredScheme = !$ route ->getSchemes () || $ route ->hasScheme ($ this ->context ->getScheme ());
192
196
if ($ requiredMethods ) {
193
- // HEAD and GET are equivalent as per RFC
194
- if ('HEAD ' === $ method = $ this ->context ->getMethod ()) {
195
- $ method = 'GET ' ;
196
- }
197
-
198
197
if (!\in_array ($ method , $ requiredMethods )) {
199
198
if ($ hasRequiredScheme ) {
200
199
$ this ->allow = array_merge ($ this ->allow , $ requiredMethods );
0 commit comments