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

Function getRoutePattern

coderd/httpmw/httproute.go:47–71  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

45}
46
47func getRoutePattern(r *http.Request) string {
48 rctx := chi.RouteContext(r.Context())
49 if rctx == nil {
50 return ""
51 }
52
53 routePath := r.URL.Path
54 if r.URL.RawPath != "" {
55 routePath = r.URL.RawPath
56 }
57
58 tctx := chi.NewRouteContext()
59 routes := rctx.Routes
60 if routes != nil && !routes.Match(tctx, r.Method, routePath) {
61 // No matching pattern. /api/* requests will be matched as "UNKNOWN"
62 // All other ones will be matched as "STATIC".
63 if strings.HasPrefix(routePath, "/api/") {
64 return "UNKNOWN"
65 }
66 return "STATIC"
67 }
68
69 // tctx has the updated pattern, since Match mutates it
70 return tctx.RoutePattern()
71}

Callers 1

HTTPRouteFunction · 0.85

Calls 2

MatchMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected