From 87bf4d7efba00b1aa3abd6b5740f9c54546db32c Mon Sep 17 00:00:00 2001 From: Hiroki Yorimitsu <52403055+hyorimitsu@users.noreply.github.com> Date: Thu, 16 Jul 2026 10:35:23 +0900 Subject: [PATCH] docs: correct Any godoc to reflect true arbitrary-method matching --- echo.go | 8 ++++---- echo_test.go | 14 ++++++++++++++ router.go | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/echo.go b/echo.go index 297706ffc..1b231f163 100644 --- a/echo.go +++ b/echo.go @@ -578,11 +578,11 @@ func (e *Echo) RouteNotFound(path string, h HandlerFunc, m ...MiddlewareFunc) Ro return e.Add(RouteNotFound, path, h, m...) } -// Any registers a new route for all HTTP methods (supported by Echo) and path with matching handler -// in the router with optional route-level middleware. +// Any registers a new route for a path with matching handler in the router with optional +// route-level middleware. Panics on error. The route matches any HTTP method in the request, +// including methods not known to Echo, by registering a single RouteAny route. // -// Note: this method only adds specific set of supported HTTP methods as handler and is not true -// "catch-any-arbitrary-method" way of matching requests. +// A method-specific route registered for the same path takes precedence over the Any route. func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) RouteInfo { return e.Add(RouteAny, path, handler, middleware...) } diff --git a/echo_test.go b/echo_test.go index 46a175eaf..7d2266c13 100644 --- a/echo_test.go +++ b/echo_test.go @@ -942,6 +942,20 @@ func TestEcho_Any(t *testing.T) { assert.Equal(t, `OK from ANY`, body) } +func TestEcho_Any_matchesArbitraryMethod(t *testing.T) { + e := New() + + e.Any("/activate", func(c *Context) error { + return c.String(http.StatusTeapot, "OK from ANY") + }) + + // ARBITRARY-METHOD is not one of Echo's known HTTP methods; the RouteAny + // fallback must still match it. + status, body := request("ARBITRARY-METHOD", "/activate", e) + assert.Equal(t, http.StatusTeapot, status) + assert.Equal(t, `OK from ANY`, body) +} + func TestEcho_Any_hasLowerPriority(t *testing.T) { e := New() diff --git a/router.go b/router.go index e315b75a9..9d12f958e 100644 --- a/router.go +++ b/router.go @@ -485,7 +485,7 @@ func (r *DefaultRouter) Remove(method string, path string) error { } // AddRouteError is error returned by Router.Add containing information what actual route adding failed. Useful for -// mass adding (i.e. Any() routes) +// mass adding (i.e. Match() routes) type AddRouteError struct { Err error Method string