@@ -108,7 +108,12 @@ public function match(\$pathinfo)
108
108
\$trimmedPathinfo = rtrim( \$pathinfo, '/');
109
109
\$context = \$this->context;
110
110
\$request = \$this->request;
111
- \$requestMethod = \$context->getMethod();
111
+ \$requestMethod = \$isLikeGetMethod = \$context->getMethod();
112
+
113
+ if ( \$requestMethod === 'HEAD') {
114
+ \$isLikeGetMethod = 'GET';
115
+ }
116
+
112
117
113
118
$ code
114
119
@@ -219,11 +224,6 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
219
224
$ hostMatches = false ;
220
225
$ methods = $ route ->getMethods ();
221
226
222
- // GET and HEAD are equivalent
223
- if (in_array ('GET ' , $ methods ) && !in_array ('HEAD ' , $ methods )) {
224
- $ methods [] = 'HEAD ' ;
225
- }
226
-
227
227
$ supportsTrailingSlash = $ supportsRedirections && (!$ methods || in_array ('HEAD ' , $ methods ));
228
228
$ regex = $ compiledRoute ->getRegex ();
229
229
@@ -265,20 +265,40 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
265
265
EOF ;
266
266
267
267
$ gotoname = 'not_ ' .preg_replace ('/[^A-Za-z0-9_]/ ' , '' , $ name );
268
+
268
269
if ($ methods ) {
269
270
if (1 === count ($ methods )) {
270
- $ code .= <<<EOF
271
- if ( \$requestMethod != ' $ methods [0 ]') {
271
+ if ($ methods [0 ] === 'HEAD ' ) {
272
+ $ code .= <<<EOF
273
+ if ( \$requestMethod != 'HEAD') {
274
+ \$allow[] = 'HEAD';
275
+ goto $ gotoname;
276
+ }
277
+
278
+
279
+ EOF ;
280
+ } else {
281
+ $ code .= <<<EOF
282
+ if ( \$isLikeGetMethod != ' $ methods [0 ]') {
272
283
\$allow[] = ' $ methods [0 ]';
273
284
goto $ gotoname;
274
285
}
275
286
276
287
277
288
EOF ;
289
+ }
278
290
} else {
291
+ $ methodVariable = 'requestMethod ' ;
292
+
293
+ if (in_array ('GET ' , $ methods )) {
294
+ // Since we treat HEAD requests like GET requests we don't need to match it.
295
+ $ methodVariable = 'isLikeGetMethod ' ;
296
+ $ methods = array_filter ($ methods , function ($ method ) { return $ method != 'HEAD ' ; });
297
+ }
298
+
279
299
$ methods = implode ("', ' " , $ methods );
280
300
$ code .= <<<EOF
281
- if (!in_array( \$requestMethod , array('$ methods'))) {
301
+ if (!in_array( \$$ methodVariable , array(' $ methods'))) {
282
302
\$allow = array_merge( \$allow, array(' $ methods'));
283
303
goto $ gotoname;
284
304
}
0 commit comments