Feature Request: Automatic HEAD request handling
还没有人认领这个 Issue。
评估
调研方向
从路由注册入口 e.GET() 开始,并将其与提议的 middleware.AutoHead() 方法进行比较。检查现有的路由器和路由注册行为,然后确定在不存在显式 HEAD 路由时,自动 HEAD 处理应如何工作。完成的标准是:GET 路由能够处理 HEAD 请求并省略响应体,同时不改变显式 HEAD 的行为。
由索引模型根据 Issue 内容生成。
描述
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?
- 主要语言
- Go
- 星标
- 32.7k
- 派生
- 2.8k
- 平均合并
- 9 小时 39 分钟
- 30 天内合并 PR
- 6
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
labstack/echo 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
-
难度 3/5 1-2 天 新手友好度 65/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 3/5 1-2 天 新手友好度 74/100
-
难度 5/5 一周以上 新手友好度 35/100
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 90/100
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
santhosh-tekuri/jsonschema#276 ·