Skip to content

expvar: avoid conflict with user-defined "GET /" route. #65745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/expvar/expvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand All @@ -23,6 +24,7 @@ package expvar

import (
"encoding/json"
"internal/godebug"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -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))
}
Expand Down