Description
The documentation comment for Echo.Any in Echo v5 appears to be inconsistent with its implementation and router behavior.
In v5.3.0 and the current master branch, the Echo.Any documentation comment says:
// 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.
However, Echo.Any registers a single RouteAny route:
func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) RouteInfo {
return e.Add(RouteAny, path, handler, middleware...)
}
RouteAny is itself documented as:
// RouteAny is special method type that matches any HTTP method in request. Any has lower
// priority that other methods that have been registered with Router to that path.
RouteAny = "echo_route_any"
For a matched path, the router also falls back to the route stored in m.any when no route for the specific request method is found. Therefore, an Any route appears to match arbitrary methods, including methods that are not explicitly enumerated or otherwise known to Echo.
This differs from the v4 behavior, where Any registered each method from the predefined methods list separately.
Version
- Echo v5.3.0
- Current
master as of July 15, 2026 (70b31c2)
The behavior appears to have been introduced as part of the v5 changes in commit:
Minimal reproduction
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v5"
)
func TestAnyMatchesArbitraryMethod(t *testing.T) {
e := echo.New()
e.Any("/example", func(c *echo.Context) error {
return c.NoContent(http.StatusNoContent)
})
req := httptest.NewRequest("ARBITRARY-METHOD", "/example", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
if rec.Code != http.StatusNoContent {
t.Fatalf("expected status %d, got %d", http.StatusNoContent, rec.Code)
}
}
The request is handled by the Any route even though ARBITRARY-METHOD is not one of Echo's predefined HTTP methods.
Expected documentation
If the current behavior is intentional, I think the comment should say that Any registers a catch-all route that matches arbitrary HTTP methods when no method-specific route matches.
For example:
// Any registers a route that matches any HTTP method.
//
// A method-specific route takes precedence over an Any route registered for the same path.
If arbitrary-method matching is not intentional, the implementation may need to be changed instead.
I’d be happy to submit a PR once the intended behavior is confirmed.
Description
The documentation comment for
Echo.Anyin Echo v5 appears to be inconsistent with its implementation and router behavior.In v5.3.0 and the current
masterbranch, theEcho.Anydocumentation comment says:However,
Echo.Anyregisters a singleRouteAnyroute:RouteAnyis itself documented as:For a matched path, the router also falls back to the route stored in
m.anywhen no route for the specific request method is found. Therefore, anAnyroute appears to match arbitrary methods, including methods that are not explicitly enumerated or otherwise known to Echo.This differs from the v4 behavior, where
Anyregistered each method from the predefinedmethodslist separately.Version
masteras of July 15, 2026 (70b31c2)The behavior appears to have been introduced as part of the v5 changes in commit:
f071367— V5 changesMinimal reproduction
The request is handled by the
Anyroute even thoughARBITRARY-METHODis not one of Echo's predefined HTTP methods.Expected documentation
If the current behavior is intentional, I think the comment should say that
Anyregisters a catch-all route that matches arbitrary HTTP methods when no method-specific route matches.For example:
If arbitrary-method matching is not intentional, the implementation may need to be changed instead.
I’d be happy to submit a PR once the intended behavior is confirmed.