Skip to content

[NFR]: Include HEAD request method in route definition when using GET #17649

Description

@raicabogdan

Is your feature request related to a problem? Please describe.
I was doing an audit on my site and the AI was talking about my site responding with 404 on HEAD requests, which I guess is expected since all my $router->add() contains just the method I use, be it GET, POST, PATCH etc. but never included HEAD in any of my routes. But the AI also reported bellow... which is an interesting afterthought.

  Why it belongs in the framework
  - The HTTP spec requires it. RFC 9110 §9.1 says general-purpose servers MUST
    support GET and HEAD, and HEAD must return the same status and headers as
    GET.
  - Most major frameworks already do it:
    - Laravel: Route::get() registers ['GET', 'HEAD'].
    - Symfony: a route that allows GET also matches HEAD.
    - Rails, Flask, Express: GET routes answer HEAD automatically.
  - Phalcon's current behaviour is the unusual one, which is your strongest
    argument in the issue or PR.

In my case, general-purpose server is my nginx, which does allow HEAD request method to pass through to the app, and the router then returns 404.

Describe the solution you'd like
An idea of what I am using currently in my Route attribute class

    public function getMethods(): array
    {
        $methods = array_flip(array_map('strtoupper', $this->methods));
        if (isset($methods['GET'])) {
            $methods['HEAD'] = true;
        }

        /** @var TMethods */
        return array_keys($methods);
    }

Describe alternatives you've considered
I've not yet checked the source code, as this is not really a high priority for me, but could be nice include in v7

Additional context
Other frameworks like laravel seem to be doing something similar to my approach. We can also try doing it by setting HEAD by default like symfony with GET requests, but only if no methods are passed. But if user has created a route and passed [GET] only, we can ignore it.

This allows for those that want more control / strictness to their routes.

My workaround was to add HEAD to all my GET routes, as there's no harm to it, so will have to decide, if this feature request is to be made, which way to proceed.

Activity

  1. added
    new feature request
    on Oct 2, 2026
  2. self-assigned this
    on Oct 7, 2026
  3. added theissue type on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0new feature request

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions