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
- net/http: ServeMux forcibly cleans double forward slash in URLs even when behaving as a gateway #42244 (closed)
- net/http: cannot register ServeMux handler for all CONNECT requests regardless of host or path #9561 (closed)
- net/http: ServeMux not validating methods for redirected paths #69690 (closed)
- net/http: Pattern matching of ServeMux works weird and unexpected #70311 (closed)
- net/http: 301 instead of 404 for unmatched requests #65624 (closed)
- net/http: ServeMux.Handler does not populate named path wildcards #69623 (closed)
- net/http: infinite redirect loop with use of path variables #70832 (closed)
- net/http: muxer no longer redirects host patterns in go1.10 #23183 (closed)
Related Code Changes
- net/http: redirect host-based patterns to trailing slash
- net/http: make ServeMux preserve query string during redirects
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)