Fixes #66405
Change-Id: Icd80944b6ca081aa7addd4fb85d2b3c29b6c9542
GitHub-Last-Rev:
c6e32742c4b733230c82627571b423de45997c24
GitHub-Pull-Request: golang/go#66618
Reviewed-on: https://go-review.googlesource.com/c/go/+/574997
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
--- /dev/null
+pkg net/http, type Request struct, Pattern string #66405
--- /dev/null
+For inbound requests, the new [Request.Pattern] field contains the [ServeMux]
+pattern (if any) that matched the request. This field is not set when
+`GODEBUG=httpmuxgo121=1` is set.
// redirects.
Response *Response
+ // Pattern is the [ServeMux] pattern that matched the request.
+ // It is empty if the request was not matched against a pattern.
+ Pattern string
+
// ctx is either the client or server context. It should only
// be modified via copying the whole Request using Clone or WithContext.
// It is unexported to prevent people from using Context wrong
}
}
-func TestPathValue(t *testing.T) {
+func TestPathValueAndPattern(t *testing.T) {
for _, test := range []struct {
pattern string
url string
t.Errorf("%q, %q: got %q, want %q", test.pattern, name, got, want)
}
}
+ if r.Pattern != test.pattern {
+ t.Errorf("pattern: got %s, want %s", r.Pattern, test.pattern)
+ }
})
server := httptest.NewServer(mux)
defer server.Close()
if use121 {
h, _ = mux.mux121.findHandler(r)
} else {
- h, _, r.pat, r.matches = mux.findHandler(r)
+ h, r.Pattern, r.pat, r.matches = mux.findHandler(r)
}
h.ServeHTTP(w, r)
}