Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
Expand Down
14 changes: 14 additions & 0 deletions echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading