diff --git a/src/expvar/expvar.go b/src/expvar/expvar.go index 954d63d17f52b1..5e9034e5d7a976 100644 --- a/src/expvar/expvar.go +++ b/src/expvar/expvar.go @@ -4,7 +4,8 @@ // Package expvar provides a standardized interface to public variables, such // as operation counters in servers. It exposes these variables via HTTP at -// /debug/vars in JSON format. +// /debug/vars in JSON format. As of Go 1.22, the /debug/vars request must +// use GET. // // Operations to set or modify these public variables are atomic. // @@ -23,6 +24,7 @@ package expvar import ( "encoding/json" + "internal/godebug" "log" "math" "net/http" @@ -381,7 +383,11 @@ func memstats() any { } func init() { - http.HandleFunc("/debug/vars", expvarHandler) + if godebug.New("httpmuxgo121").Value() == "1" { + http.HandleFunc("/debug/vars", expvarHandler) + } else { + http.HandleFunc("GET /debug/vars", expvarHandler) + } Publish("cmdline", Func(cmdline)) Publish("memstats", Func(memstats)) }