This commit is contained in:
a 2022-09-29 11:55:50 -05:00
parent be9e6aaa81
commit c37350a81f
2 changed files with 22 additions and 6 deletions

View File

@ -9,11 +9,13 @@ const rootTemplate = `<!doctype html>
<html>
<head><title>PProf Web Interface</title></head>
<body>
<p>Upload a file to explore it using the <a href="https://github.com/google/pprof">Pprof</a> web interface.
the source code <a href="https://github.com/evanj/pprofweb">over here </a>.
<p>Upload a file to explore it using the <a href="https://github.com/google/pprof">Pprof</a> web interface.</p>
<p>
the source code <a href="https://git.tuxpa.in/a/pprofweb">over here </a>.
</p>
<p>
code is based off <a href="https://github.com/evanj/pprofweb">this project</a>.
</p>
<p>
@ -42,6 +44,15 @@ works with whatever works in the command line (it just runs go tool pprof in the
<form method="post" action="/upload" enctype="multipart/form-data">
<p>Upload file: <input type="file" name="file"> <input type="submit" value="Upload"></p>
</form>
<p>
u can also use curl! basically it checks if your Accept headers have "http", and if not, then it will not redirect, and will send the id instead
curl -F file=@<filename> https://pprof.aaaaa.news/upload
</p>
</body>
</html>
`

View File

@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path"
"strings"
"sync"
"time"
@ -168,15 +169,20 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) error {
if err != nil {
return err
}
for _, h := range r.Header.Values("Accept") {
if strings.Contains(h, "text/html") {
http.Redirect(w, r, instance.id.String()+"/", http.StatusSeeOther)
return nil
}
}
w.Write([]byte(instance.id.String()))
return nil
}
type Instance struct {
id xid.ID
dat []byte
setup sync.Once
handler http.Handler
mu sync.RWMutex
@ -204,7 +210,6 @@ func (i *Instance) startHTTP(args *driver.HTTPServerArgs) error {
r := chi.NewRouter()
for pattern, handler := range args.Handlers {
jpat := "/" + path.Join(i.id.String(), pattern)
log.Println(jpat)
r.Handle(jpat, handler)
r.Handle(jpat+"/", handler)
}