Skip to content

Echo.Any documentation is inconsistent with v5 router behavior #3044

Description

@hyorimitsu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions