]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix ServeMux pattern registration
authorJonathan Amsterdam <jba@google.com>
Thu, 5 Oct 2023 15:27:36 +0000 (11:27 -0400)
committerJonathan Amsterdam <jba@google.com>
Thu, 5 Oct 2023 19:03:37 +0000 (19:03 +0000)
When the httpmuxgo121 GODEBUG setting was active, we were registering
patterns in the old and the new way. Fix to register only in the old
way.

Change-Id: Ibc1fd41e7f4d162ee5bc34575df409e1db5657cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/533095
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Olena Synenka <olenasynenka@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/server.go

index bfd27453185fbd617e00949e6514418493beeed1..7fa785dfeeb3c3a13b532754e7ed57ba654a4536 100644 (file)
@@ -2686,8 +2686,9 @@ func (mux *ServeMux) ServeHTTP(w ResponseWriter, r *Request) {
 func (mux *ServeMux) Handle(pattern string, handler Handler) {
        if use121 {
                mux.mux121.handle(pattern, handler)
+       } else {
+               mux.register(pattern, handler)
        }
-       mux.register(pattern, handler)
 }
 
 // HandleFunc registers the handler function for the given pattern.
@@ -2696,8 +2697,9 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
 func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
        if use121 {
                mux.mux121.handleFunc(pattern, handler)
+       } else {
+               mux.register(pattern, HandlerFunc(handler))
        }
-       mux.register(pattern, HandlerFunc(handler))
 }
 
 // Handle registers the handler for the given pattern in [DefaultServeMux].
@@ -2705,8 +2707,9 @@ func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Re
 func Handle(pattern string, handler Handler) {
        if use121 {
                DefaultServeMux.mux121.handle(pattern, handler)
+       } else {
+               DefaultServeMux.register(pattern, handler)
        }
-       DefaultServeMux.register(pattern, handler)
 }
 
 // HandleFunc registers the handler function for the given pattern in [DefaultServeMux].
@@ -2714,8 +2717,9 @@ func Handle(pattern string, handler Handler) {
 func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
        if use121 {
                DefaultServeMux.mux121.handleFunc(pattern, handler)
+       } else {
+               DefaultServeMux.register(pattern, HandlerFunc(handler))
        }
-       DefaultServeMux.register(pattern, HandlerFunc(handler))
 }
 
 func (mux *ServeMux) register(pattern string, handler Handler) {