From e14a62f1884956377b4b87bb3a23c57d7ac4753c Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 24 Jan 2017 16:55:43 -0700 Subject: [PATCH] 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. --- caddyhttp/pprof/pprof.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/caddyhttp/pprof/pprof.go b/caddyhttp/pprof/pprof.go index 9ac089423..3a0dbd93c 100644 --- a/caddyhttp/pprof/pprof.go +++ b/caddyhttp/pprof/pprof.go @@ -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)