Feature Request: Automatic HEAD request handling
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 32.7k
- Fork
- 2.8k
- Merge medio
- 9h 35m
- PR unite (30g)
- 6
Descrizione
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?
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal punto di ingresso per la registrazione delle route e.GET() e confrontalo con l’approccio proposto middleware.AutoHead(). Esamina il comportamento esistente del router e della registrazione delle route, quindi determina come dovrebbe funzionare la gestione automatica di HEAD quando non esiste una route HEAD esplicita. Il lavoro è completato quando le route GET gestiscono le richieste HEAD omettendo i corpi delle risposte, senza modificare il comportamento esplicito di HEAD.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- go
- Ambito
- api, backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100