0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2025-01-06 22:40:31 -05:00

pprof: Set proper Content-Type header

The standard lib pprof library doesn't set its own Content-Type header
properly. If pprof is used with gzip, the index endpoint will be
interpreted as a .gz file; so we force its hand and set the header.
This commit is contained in:
Matthew Holt 2017-01-24 16:55:43 -07:00
parent 94e382ef0a
commit e14a62f188
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -32,7 +32,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
// https://golang.org/src/net/http/pprof/pprof.go#L67
func NewMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc(BasePath+"/", pp.Index)
mux.HandleFunc(BasePath+"/", func(w http.ResponseWriter, r *http.Request) {
// this endpoint, as implemented in the standard library, doesn't set
// its Content-Type header, so using this can confuse clients, especially
// if gzipping...
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pp.Index(w, r)
})
mux.HandleFunc(BasePath+"/cmdline", pp.Cmdline)
mux.HandleFunc(BasePath+"/profile", pp.Profile)
mux.HandleFunc(BasePath+"/symbol", pp.Symbol)