diff options
| author | Nicholas Husin <husin@google.com> | 2025-08-29 10:34:10 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-08-31 05:18:41 -0700 |
| commit | 6a08e80399bd65b95e60e3c74b7e1f86754752a7 (patch) | |
| tree | 602f51e04b262aac490badcb0d84b5a46b32f724 /src/net/http/server.go | |
| parent | 8bcda6c79d40f49363cd04cdaf5bd7909de8f94f (diff) | |
| download | go-6a08e80399bd65b95e60e3c74b7e1f86754752a7.tar.xz | |
net/http: skip redirecting in ServeMux when URL path for CONNECT is empty
In 1.21 ServeMux, we had a special-case to skip redirection when a given
path is empty for CONNECT requests:
https://go.googlesource.com/go/+/refs/tags/go1.24.4/src/net/http/servemux121.go#205.
This special case seems to not have been carried over to 1.22 ServeMux.
This causes needless redirection, which this CL fixes.
Fixes #74422
Change-Id: I3cc5b4d195ab0591a9139225b632cbe17f4290db
Reviewed-on: https://go-review.googlesource.com/c/go/+/699915
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index cf0bd0a91d..6fdcd51c0a 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2759,9 +2759,12 @@ func (mux *ServeMux) matchOrRedirect(host, method, path string, u *url.URL) (_ * defer mux.mu.RUnlock() n, matches := mux.tree.match(host, method, path) - // If we have an exact match, or we were asked not to try trailing-slash redirection, - // or the URL already has a trailing slash, then we're done. - if !exactMatch(n, path) && u != nil && !strings.HasSuffix(path, "/") { + // We can terminate here if any of the following is true: + // - We have an exact match already. + // - We were asked not to try trailing slash redirection. + // - The URL already has a trailing slash. + // - The URL is an empty string. + if !exactMatch(n, path) && u != nil && !strings.HasSuffix(path, "/") && path != "" { // If there is an exact match with a trailing slash, then redirect. path += "/" n2, _ := mux.tree.match(host, method, path) |
