]> Cypherpunks repositories - gostls13.git/commit
net/http/pprof: avoid panic with user-defined "GET /" route
authorMatteo Vaccari <matteo.vaccari@gmail.com>
Thu, 22 Feb 2024 11:36:38 +0000 (11:36 +0000)
committerJonathan Amsterdam <jba@google.com>
Tue, 27 Feb 2024 17:34:05 +0000 (17:34 +0000)
commit9fcffc53593c5cd103630d0d24ef8bd91e17246d
treedaa1e1f9751d799dabbd640c90adf71064bf0bf2
parent05845747971c0163c435c35ae8ada07c0fb3b7a8
net/http/pprof: avoid panic with user-defined "GET /" route

With the new routing style in go 1.22, declaring

    http.Handle("GET /", h)

generates a conflict with route "/debug/pprof/" and the others declared in
the net/http/pprof package. You get an error such as:

panic: pattern "GET /" (registered at .../pprof.go:94): GET / matches
fewer methods than /debug/pprof/, but has a more general path pattern

This patch prevents that error.  Adding GET is correct because no other
method makes sense with the /debug/pprof routes. However, a tool using any
method other than GET will break.

We preserve the traditional behaviour when GODEBUG=httpmuxgo121=1 is
specified.

Updates #65723

Change-Id: I49c21f5f3e802ad7538062d824354b2e4d8a800e
GitHub-Last-Rev: 35e4012663f454fee8f00a321c43592ce4754feb
GitHub-Pull-Request: golang/go#65791
Reviewed-on: https://go-review.googlesource.com/c/go/+/565176
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
src/net/http/pprof/pprof.go