Browse Source

[Bug Fix] Propagate query args during URL redirect to preserve heap allocation type (#445)

Propagate query args during URL redirect to preserve heap allocation type
Richard Artoul 6 years ago
parent
commit
3ea8567a2e
1 changed files with 8 additions and 1 deletions
  1. 8
    1
      internal/driver/webui.go

+ 8
- 1
internal/driver/webui.go View File

179
 	// https://github.com/google/pprof/pull/348
179
 	// https://github.com/google/pprof/pull/348
180
 	mux := http.NewServeMux()
180
 	mux := http.NewServeMux()
181
 	mux.Handle("/ui/", http.StripPrefix("/ui", handler))
181
 	mux.Handle("/ui/", http.StripPrefix("/ui", handler))
182
-	mux.Handle("/", http.RedirectHandler("/ui/", http.StatusTemporaryRedirect))
182
+	mux.Handle("/", redirectWithQuery("/ui"))
183
 	s := &http.Server{Handler: mux}
183
 	s := &http.Server{Handler: mux}
184
 	return s.Serve(ln)
184
 	return s.Serve(ln)
185
 }
185
 }
186
 
186
 
187
+func redirectWithQuery(path string) http.HandlerFunc {
188
+	return func(w http.ResponseWriter, r *http.Request) {
189
+		pathWithQuery := &gourl.URL{Path: path, RawQuery: r.URL.RawQuery}
190
+		http.Redirect(w, r, pathWithQuery.String(), http.StatusTemporaryRedirect)
191
+	}
192
+}
193
+
187
 func isLocalhost(host string) bool {
194
 func isLocalhost(host string) bool {
188
 	for _, v := range []string{"localhost", "127.0.0.1", "[::1]", "::1"} {
195
 	for _, v := range []string{"localhost", "127.0.0.1", "[::1]", "::1"} {
189
 		if host == v {
196
 		if host == v {