Parcourir la 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 il y a 6 ans
Parent
révision
3ea8567a2e
1 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 8
    1
      internal/driver/webui.go

+ 8
- 1
internal/driver/webui.go Voir le fichier

@@ -179,11 +179,18 @@ func defaultWebServer(args *plugin.HTTPServerArgs) error {
179 179
 	// https://github.com/google/pprof/pull/348
180 180
 	mux := http.NewServeMux()
181 181
 	mux.Handle("/ui/", http.StripPrefix("/ui", handler))
182
-	mux.Handle("/", http.RedirectHandler("/ui/", http.StatusTemporaryRedirect))
182
+	mux.Handle("/", redirectWithQuery("/ui"))
183 183
 	s := &http.Server{Handler: mux}
184 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 194
 func isLocalhost(host string) bool {
188 195
 	for _, v := range []string{"localhost", "127.0.0.1", "[::1]", "::1"} {
189 196
 		if host == v {