]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: give ServeMux.handler a better name
authorJonathan Amsterdam <jba@google.com>
Wed, 13 Sep 2023 20:00:45 +0000 (16:00 -0400)
committerJonathan Amsterdam <jba@google.com>
Wed, 13 Sep 2023 21:00:43 +0000 (21:00 +0000)
Change-Id: I27bb7d9d5f172a84aa31304194b8a13036b9c5d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/528275
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/net/http/server.go

index 7ce078ced41b79a4fa95a544d46356719c9ceeaa..74362a69ad763786dcd7ab7866ea73118725c4eb 100644 (file)
@@ -2428,13 +2428,13 @@ func (mux *ServeMux) findHandler(r *Request) (h Handler, patStr string) {
                // If r.URL.Path is /tree and its handler is not registered,
                // the /tree -> /tree/ redirect applies to CONNECT requests
                // but the path canonicalization does not.
-               _, _, u := mux.handler(r.URL.Host, r.Method, path, r.URL)
+               _, _, u := mux.matchOrRedirect(r.URL.Host, r.Method, path, r.URL)
                if u != nil {
                        return RedirectHandler(u.String(), StatusMovedPermanently), u.Path
                }
                // Redo the match, this time with r.Host instead of r.URL.Host.
                // Pass a nil URL to skip the trailing-slash redirect logic.
-               n, _, _ = mux.handler(r.Host, r.Method, path, nil)
+               n, _, _ = mux.matchOrRedirect(r.Host, r.Method, path, nil)
        } else {
                // All other requests have any port stripped and path cleaned
                // before passing to mux.handler.
@@ -2444,7 +2444,7 @@ func (mux *ServeMux) findHandler(r *Request) (h Handler, patStr string) {
                // If the given path is /tree and its handler is not registered,
                // redirect for /tree/.
                var u *url.URL
-               n, _, u = mux.handler(host, r.Method, path, r.URL)
+               n, _, u = mux.matchOrRedirect(host, r.Method, path, r.URL)
                if u != nil {
                        return RedirectHandler(u.String(), StatusMovedPermanently), u.Path
                }
@@ -2465,18 +2465,14 @@ func (mux *ServeMux) findHandler(r *Request) (h Handler, patStr string) {
        return n.handler, n.pattern.String()
 }
 
-// handler looks up a node in the tree that matches the host, method and path.
+// matchOrRedirect looks up a node in the tree that matches the host, method and path.
 // The path is known to be in canonical form, except for CONNECT methods.
 
 // If the url argument is non-nil, handler also deals with trailing-slash
 // redirection: when a path doesn't match exactly, the match is tried again
-
 // after appending "/" to the path. If that second match succeeds, the last
 // return value is the URL to redirect to.
-//
-// TODO(jba): give this a better name. For now we're keeping the name of the closest
-// corresponding function in the original code.
-func (mux *ServeMux) handler(host, method, path string, u *url.URL) (_ *routingNode, matches []string, redirectTo *url.URL) {
+func (mux *ServeMux) matchOrRedirect(host, method, path string, u *url.URL) (_ *routingNode, matches []string, redirectTo *url.URL) {
        mux.mu.RLock()
        defer mux.mu.RUnlock()