From b49eba8fe1ef3e31bf544134a864807e76f99ec3 Mon Sep 17 00:00:00 2001 From: Fabricio Date: Sat, 27 Jul 2019 10:57:16 -0300 Subject: [PATCH] better url path parsing --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 860acf7..c1ed60d 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "net/http/httputil" "net/url" "os" + "path" "path/filepath" "plugin" "strings" @@ -101,7 +102,7 @@ func NewDashboardHTMLHandler(config Config) http.HandlerFunc { // NewDashboardRetryHandler retries a request func NewDashboardRetryHandler(srv *CaptureService, next http.HandlerFunc) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { - id := req.URL.Path[strings.LastIndex(req.URL.Path, "/")+1:] + id := path.Base(req.URL.Path) capture := srv.Find(id) reqBody, _ := ioutil.ReadAll(capture.Req.Body) @@ -119,7 +120,7 @@ func NewDashboardRetryHandler(srv *CaptureService, next http.HandlerFunc) http.H // NewDashboardInfoHandler returns the full capture info func NewDashboardInfoHandler(srv *CaptureService) http.HandlerFunc { return func(rw http.ResponseWriter, req *http.Request) { - id := req.URL.Path[strings.LastIndex(req.URL.Path, "/")+1:] + id := path.Base(req.URL.Path) capture := srv.Find(id) rw.Header().Add("Content-Type", "application/json") json.NewEncoder(rw).Encode(dump(capture))