diff --git a/router.go b/router.go index 558c9e8e1..0db3bc04c 100644 --- a/router.go +++ b/router.go @@ -1039,8 +1039,8 @@ func (r *DefaultRouter) Route(c *Context) HandlerFunc { } c.InitializeRoute(rInfo, &pathValues) - c.SetPath(rPath) // after InitializeRoute so we would not accidentally change `notFoundRouteInfo` or `methodNotAllowedRouteInfo` Path - + c.SetPath(rPath) // after InitializeRoute so we would not accidentally change `notFoundRouteInfo` or `methodNotAllowedRouteInfo` Path + c.request.Pattern = rPath // help standard library based middlewares. This is a deliberate choice not to call `request.SetPathValue` for params. return rHandler } diff --git a/router_test.go b/router_test.go index e69512c8b..1dd306a36 100644 --- a/router_test.go +++ b/router_test.go @@ -671,6 +671,21 @@ func checkUnusedParamValues(t *testing.T, c *Context, expectParam map[string]str } } +func TestRouterFillsRequestPatternField(t *testing.T) { + path := "/folders/a/files/echo.gif" + req := httptest.NewRequest(http.MethodGet, path, nil) + rec := httptest.NewRecorder() + + e := New() + e.GET(path, handlerFunc) + + c := e.NewContext(req, rec) + _ = e.router.Route(c) + + assert.Equal(t, path, c.Path()) + assert.Equal(t, path, c.Request().Pattern) +} + func TestRouterStatic(t *testing.T) { path := "/folders/a/files/echo.gif" req := httptest.NewRequest(http.MethodGet, path, nil)