Feature Request: Automatic HEAD request handling
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start at the e.GET() route-registration entry point and compare it with the proposed middleware.AutoHead() approach. Review the existing router and route-registration behavior, then determine how automatic HEAD handling should work when no explicit HEAD route exists. Done means GET routes serve HEAD requests with response bodies omitted without changing explicit HEAD behavior.
Written by the indexing model from the issue text.
Description
Currently, Echo requires explicit HEAD route registration for every GET route. Some other frameworks like Fiber, Express and Fastify handle this automatically. According to HTTP semantics, HEAD should behave identically to GET except that the response body is omitted. Automatically supporting HEAD for GET routes aligns with this expectation and reduces boilerplate.
Related: #654
Proposal
Add automatic HEAD handling for GET routes when no explicit HEAD route is registered.
Implementation Options
Option 1: Middleware approach
e := echo.New()
e.Use(middleware.AutoHead())
Pros:
- Opt-in
- No changes to core routing
- Simple implementation
Cons:
- Must be registered last in the middleware chain. Otherwise, middlewares registered after it will not execute for HEAD requests, since the middleware directly invokes the handler and bypasses the remaining chain
I've already implemented this approach, but after testing I realized the middleware ordering requirement makes it less convenient and more error-prone.
Option 2: Core integration
Auto-register HEAD routes during e.GET() calls, controlled by config :
e := echo.New()
e.AutoHead = true
Default value could remain false to avoid breaking existing behavior.
Pros:
- No middleware ordering constraints
- Slightly better performance, since re-routing is avoided
Cons:
- Requires changes to core Echo router/route registration
Questions
- Would the Echo team be interested in this functionality?
- If so, which implementation approach would be preferred: middleware or core integration? Would you consider a PR for either approach?
- Dominant language
- Go
- Stars
- 32.7k
- Forks
- 2.8k
- Avg merge
- 9h 39m
- Merged PRs (30d)
- 6
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from labstack/echo
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Similar issues
-
needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
bug carvel-triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
carvel-dev/kapp-controller#1861 ·
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100