Skip to content

net/http: ServeMux with CONNECT and empty path broke in 1.22 #74422

Open
@thorrez

Description

@thorrez

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions