Label a request with an empty path by the / route in metrics
When both r.URL.Path and r.URL.RawPath are empty, as for the request line GET http://pixa.example HTTP/1.1, chi routes the request as /, but routePattern asked Find about the empty path and labelled it unmatched. It now uses / then, as chi does. After the rebase onto next, the TODO.md entry is back at the top of Completed Steps. Model: opus-5-5
This commit is contained in:
@@ -239,7 +239,7 @@ func (s *Middleware) Metrics() func(http.Handler) http.Handler {
|
||||
// "unmatched" when it matches none or is not served by a chi router. The
|
||||
// metrics library takes the label before the request is routed, so the
|
||||
// router is asked which route matches, with the path it routes on:
|
||||
// r.URL.RawPath when set, else r.URL.Path.
|
||||
// r.URL.RawPath when set, else r.URL.Path, else /.
|
||||
func routePattern(r *http.Request) string {
|
||||
pattern := ""
|
||||
|
||||
@@ -250,6 +250,10 @@ func routePattern(r *http.Request) string {
|
||||
path = r.URL.Path
|
||||
}
|
||||
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
|
||||
pattern = rctx.Routes.Find(chi.NewRouteContext(), r.Method, path)
|
||||
|
||||
// For the path a subrouter is mounted at, such as /v1 or /v1/, Find
|
||||
|
||||
Reference in New Issue
Block a user