Go version

go version go1.24.4 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/usr/local/google/home/kthorrez/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/usr/local/google/home/kthorrez/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1660463919=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/usr/local/google/home/kthorrez/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/usr/local/google/home/kthorrez/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.24'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/usr/local/google/home/kthorrez/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.24/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

See this program: https://go.dev/play/p/u285umcCAMe

What did you see happen?

Run with go run mux.go it outputs

2025/06/28 20:41:49 Method: "CONNECT" URL: "//server.example.com:80" URL Path: "" Proto: "HTTP/1.1" URL scheme: "" Host: "server.example.com:80" URL Host: "server.example.com:80"
2025/06/28 20:41:49 Matched handler &http.redirectHandler{url:"//", code:301} with pattern "//"

So it tries to redirect to path //. That's strange. Why double slash? In fact I don't want a redirect at all. I want to be able to handle the request. If I try to register pattern "" (empty string) it panics at registration time. So registering "/" is the broadest I can get. But it doesn't match the CONNECT request. I need a way to match the CONNECT request.

This is the example CONNECT request from https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/CONNECT#proxy_authorization with the Proxy Authorization deleted (because it's irrelevant).

What did you expect to see?

This problem didn't exist in 1.21. If I run the program with GODEBUG=httpmuxgo121=1 go run mux.go it outputs

2025/06/28 20:43:08 Method: "CONNECT" URL: "//server.example.com:80" URL Path: "" Proto: "HTTP/1.1" URL scheme: "" Host: "server.example.com:80" URL Host: "server.example.com:80"
2025/06/28 20:43:08 Matched handler (http.HandlerFunc)(0x543dc0) with pattern ""

That's much better.

Comment From: gabyhelp

Related Issues

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: dr2chase

@neild can you give this a look?

Comment From: neild

The 1.21 ServeMux contains a special-case to skip redirecting when the path is "": https://go.googlesource.com/go/+/refs/tags/go1.24.4/src/net/http/servemux121.go#205

The 1.22 ServeMux should probably do the same.

Comment From: cagedmantis

Placed this in the backlog milestone. I'm not sure there is much to do here. Please change it if I am incorrect.

Comment From: thorrez

I think there is something to do here.

I think ServeMux should be modified to skip redirecting when the path is "", as neild suggested. (I would probably limit it to when the request path is "" and the handler is registered on "/".)

Comment From: gopherbot

Change https://go.dev/cl/699915 mentions this issue: net/http: skip redirecting in ServeMux when URL path for CONNECT is empty