Skip to content

Commit

Permalink
Fix pprof URL path
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 29, 2023
1 parent ea17c27 commit 46c8d6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
21 changes: 15 additions & 6 deletions debug_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http/pprof"
"runtime"
"runtime/debug"
"strings"

"github.com/sagernet/sing-box/common/badjson"
"github.com/sagernet/sing-box/common/humanize"
Expand Down Expand Up @@ -47,12 +48,20 @@ func applyDebugListenOption(options option.DebugOptions) {
encoder.SetIndent("", " ")
encoder.Encode(memObject)
})
r.HandleFunc("/pprof", pprof.Index)
r.HandleFunc("/pprof/*", pprof.Index)
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
r.HandleFunc("/pprof/profile", pprof.Profile)
r.HandleFunc("/pprof/symbol", pprof.Symbol)
r.HandleFunc("/pprof/trace", pprof.Trace)
r.Route("/pprof", func(r chi.Router) {
r.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
if !strings.HasSuffix(request.URL.Path, "/") {
http.Redirect(writer, request, request.URL.Path+"/", http.StatusMovedPermanently)
} else {
pprof.Index(writer, request)
}
})
r.HandleFunc("/*", pprof.Index)
r.HandleFunc("/cmdline", pprof.Cmdline)
r.HandleFunc("/profile", pprof.Profile)
r.HandleFunc("/symbol", pprof.Symbol)
r.HandleFunc("/trace", pprof.Trace)
})
})
debugHTTPServer = &http.Server{
Addr: options.Listen,
Expand Down
2 changes: 1 addition & 1 deletion debug_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux
//go:build !(linux || darwin)

package box

Expand Down
2 changes: 2 additions & 0 deletions debug_linux.go → debug_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux || darwin

package box

import (
Expand Down

0 comments on commit 46c8d6e

Please sign in to comment.