MCPcopy Index your code
hub / github.com/coder/coder / HTTPRoute

Function HTTPRoute

coderd/httpmw/httproute.go:36–45  ·  view source on GitHub ↗

HTTPRoute is middleware that stores the HTTP route pattern and method in context for use by downstream handlers and services (e.g. prometheus).

(next http.Handler)

Source from the content-addressed store, hash-verified

34// HTTPRoute is middleware that stores the HTTP route pattern and method in
35// context for use by downstream handlers and services (e.g. prometheus).
36func HTTPRoute(next http.Handler) http.Handler {
37 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
38 route := getRoutePattern(r)
39 ctx := context.WithValue(r.Context(), httpRouteInfoKey{}, httpRouteInfo{
40 Route: route,
41 Method: r.Method,
42 })
43 next.ServeHTTP(w, r.WithContext(ctx))
44 })
45}
46
47func getRoutePattern(r *http.Request) string {
48 rctx := chi.RouteContext(r.Context())

Callers 1

TestPrometheusFunction · 0.92

Calls 4

getRoutePatternFunction · 0.85
WithContextMethod · 0.80
ContextMethod · 0.65
ServeHTTPMethod · 0.45

Tested by 1

TestPrometheusFunction · 0.74