From 62bdbd2596591bb2819a1614dd3c57ffeec667e3 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Thu, 5 Oct 2023 11:27:36 -0400 Subject: [PATCH] net/http: fix ServeMux pattern registration 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 TryBot-Result: Gopher Robot Reviewed-by: Olena Synenka Reviewed-by: Damien Neil --- src/net/http/server.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index bfd27453185..7fa785dfeeb 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -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) {