diff options
Diffstat (limited to 'pathrouter/matcher.go')
| -rw-r--r-- | pathrouter/matcher.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/pathrouter/matcher.go b/pathrouter/matcher.go index 45ba818..0ddd7f6 100644 --- a/pathrouter/matcher.go +++ b/pathrouter/matcher.go @@ -49,10 +49,10 @@ // // Path matching is performed on the escaped form of the URL path, as returned by [url.URL.EscapedPath], // so any slashes that were encoded as %2F in the URL path will be considered part of a path element instead of a boundary. +// After matching, [VariableValue] calls return unescaped values. // // For instance, using the example above, the URL path "/v1/objects/42/23" would not match and generate a 404 response, -// but the URL path "/v1/objects/42%2F23" would match and invoke (e.g. with method GET) the GetObject handler with rc.Variable("id") = "42/23". -// Like in this example, [HandlerFunc] will receive a [Context] in which [Context.Variable] calls returns unescaped values. +// but the URL path "/v1/objects/42%2F23" would match and invoke (e.g. with method GET) the GetObject handler with pathrouter.VariableValue(r, "id") = "42/23". // // # Implicit normalizations // @@ -97,7 +97,7 @@ type Matcher interface { } type realMatcher struct { - accept func(path []string, rc Context) HandlerFunc + accept func(path []string, rc routingContext) http.HandlerFunc // The smallest len(path) that accept() can accept. minLength int @@ -115,12 +115,13 @@ func (m realMatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) { // TryServeHTTP implements the [Matcher] interface. func (m realMatcher) TryServeHTTP(w http.ResponseWriter, r *http.Request) bool { path := extractPath(r.URL) - rc := newContext() + var rc routingContext + r, rc = injectContext(r) handlerFunc := m.accept(path, rc) if handlerFunc == nil { return false } else { - handlerFunc(w, r, rc) + handlerFunc(w, r) return true } } |
