@@ -92,6 +92,9 @@ type Echo struct {
9292
9393 // formParseMaxMemory is passed to Context for multipart form parsing (See http.Request.ParseMultipartForm)
9494 formParseMaxMemory int64
95+
96+ // automatically registers a HEAD request within GET
97+ autoHeadInGet bool
9598}
9699
97100// JSONSerializer is the interface that encodes and decodes JSON to and from interfaces.
@@ -330,6 +333,7 @@ func New() *Echo {
330333 Binder : & DefaultBinder {},
331334 JSONSerializer : & DefaultJSONSerializer {},
332335 formParseMaxMemory : defaultMemory ,
336+ autoHeadInGet : true ,
333337 }
334338
335339 e .serveHTTPFunc = e .serveHTTP
@@ -341,6 +345,14 @@ func New() *Echo {
341345 return e
342346}
343347
348+ // AutoHeadCancel turns the flag autoHeadInGet to false.
349+ //
350+ // This flag is used to register HEAD request automatically
351+ // everytime a GET request is registered.
352+ func (e * Echo ) AutoHeadCancel () {
353+ e .autoHeadInGet = false
354+ }
355+
344356// NewContext returns a new Context instance.
345357//
346358// Note: both request and response can be left to nil as Echo.ServeHTTP will call c.Reset(req,resp) anyway
@@ -437,7 +449,14 @@ func (e *Echo) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) RouteInfo
437449
438450// GET registers a new GET route for a path with matching handler in the router
439451// with optional route-level middleware. Panics on error.
452+ //
453+ // Note: if autoHeadInGet flag is true, it will also register a HEAD request
454+ // to the same path.
440455func (e * Echo ) GET (path string , h HandlerFunc , m ... MiddlewareFunc ) RouteInfo {
456+ if e .autoHeadInGet {
457+ e .Add (http .MethodHead , path , h , m ... )
458+ }
459+
441460 return e .Add (http .MethodGet , path , h , m ... )
442461}
443462
0 commit comments