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
4 changes: 2 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading