diff --git a/README.md b/README.md index fb8e097..1125023 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ in favor of the dashboard. However, you can change the dashboard's name with `-d ##### Preview -![dashboard](https://i.imgur.com/YTukk5J.png) +![dashboard](https://i.imgur.com/5pbLRRY.png) ## Building diff --git a/config.go b/config.go index c673885..dd7115b 100644 --- a/config.go +++ b/config.go @@ -13,6 +13,7 @@ type Config struct { DashboardPath string `json:"dashboardPath"` DashboardConnPath string `json:"dashboardConnPath"` DashboardClearPath string `json:"dashboardClearPath"` + DashboardRetryPath string `json:"dashboardRetryPath"` DashboardItemInfoPath string `json:"dashboardItemInfoPath"` } @@ -26,6 +27,7 @@ func ReadConfig() Config { dashboardPath := fmt.Sprintf("/%s/", *dashboard) dashboardConnPath := fmt.Sprintf("/%s/conn/", *dashboard) dashboardClearPath := fmt.Sprintf("/%s/clear/", *dashboard) + dashboardRetryPath := fmt.Sprintf("/%s/retry/", *dashboard) dashboardItemInfoPath := fmt.Sprintf("/%s/items/", *dashboard) return Config{ @@ -36,6 +38,7 @@ func ReadConfig() Config { DashboardPath: dashboardPath, DashboardConnPath: dashboardConnPath, DashboardClearPath: dashboardClearPath, + DashboardRetryPath: dashboardRetryPath, DashboardItemInfoPath: dashboardItemInfoPath, } } diff --git a/dashboard.go b/dashboard.go index 1b4439e..d0bf31a 100644 --- a/dashboard.go +++ b/dashboard.go @@ -192,7 +192,8 @@ const dashboardHTML = `
- + +
{{request}}
@@ -239,7 +240,9 @@ const dashboardHTML = ` } $scope.clearDashboard = () => { - $http.get(<<.DashboardClearPath>>).then(clearRequestAndResponse); + $http.get(<<.DashboardClearPath>>) + .then(clearRequestAndResponse) + .then(() => $scope.selectedId = null); } function clearRequestAndResponse() { @@ -253,11 +256,7 @@ const dashboardHTML = ` return $scope[name].indexOf('Content-Type: application/json') != -1; } - $scope.canGenerateCurl = () => { - return $scope['request'] != null; - } - - $scope.generateCurl = () => { + $scope.copyCurl = () => { let e = document.createElement('textarea'); e.value = $scope.curl; document.body.appendChild(e); @@ -266,6 +265,10 @@ const dashboardHTML = ` document.body.removeChild(e); } + $scope.retry = () => { + $http.get(<<.DashboardRetryPath>> + $scope.selectedId); + } + $scope.prettifyBody = key => { let regex = /\n([\{\[](.*\s*)*[\}\]])/; let data = $scope[key]; diff --git a/main.go b/main.go index 021bfd8..d75bccd 100644 --- a/main.go +++ b/main.go @@ -27,10 +27,13 @@ func startCapture(config Config) { list := NewCaptureList(config.MaxCaptures) - http.Handle("/", NewPlugin(NewRecorder(list, NewProxyHandler(config.TargetURL)))) + handler := NewPlugin(NewRecorder(list, NewProxyHandler(config.TargetURL))) + + http.Handle("/", handler) http.Handle(config.DashboardPath, NewDashboardHtmlHandler(config)) http.Handle(config.DashboardConnPath, NewDashboardConnHandler(list)) http.Handle(config.DashboardClearPath, NewDashboardClearHandler(list)) + http.Handle(config.DashboardRetryPath, NewDashboardRetryHandler(list, handler)) http.Handle(config.DashboardItemInfoPath, NewDashboardItemInfoHandler(list)) captureHost := fmt.Sprintf("http://localhost:%s", config.ProxyPort) @@ -89,6 +92,23 @@ func NewDashboardHtmlHandler(config Config) http.Handler { }) } +func NewDashboardRetryHandler(list *CaptureList, next http.Handler) http.Handler { + return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + id := req.URL.Path[strings.LastIndex(req.URL.Path, "/")+1:] + capture := list.Find(id) + if capture == nil { + http.Error(rw, "Item Not Found", http.StatusNotFound) + return + } + var reqBody []byte + capture.Req.Body, reqBody = drain(capture.Req.Body) + r, _ := http.NewRequest(capture.Req.Method, capture.Req.URL.String(), capture.Req.Body) + r.Header = capture.Req.Header + next.ServeHTTP(rw, r) + capture.Req.Body = ioutil.NopCloser(bytes.NewReader(reqBody)) + }) +} + func NewDashboardItemInfoHandler(list *CaptureList) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { id := req.URL.Path[strings.LastIndex(req.URL.Path, "/")+1:]