add retry button
This commit is contained in:
parent
1706954423
commit
3085cb3429
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
17
dashboard.go
17
dashboard.go
|
@ -192,7 +192,8 @@ const dashboardHTML = `
|
|||
<div class="req">
|
||||
<div class="controls">
|
||||
<button ng-disabled="!canPrettifyBody('request')" ng-click="prettifyBody('request')">prettify</button>
|
||||
<button ng-disabled="!canGenerateCurl()" ng-click="generateCurl()">curl</button>
|
||||
<button ng-disabled="selectedId == null" ng-click="copyCurl()">curl</button>
|
||||
<button ng-disabled="selectedId == null" ng-click="retry()">retry</button>
|
||||
</div>
|
||||
<div class="req-inner">
|
||||
<pre>{{request}}</pre>
|
||||
|
@ -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];
|
||||
|
|
22
main.go
22
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:]
|
||||
|
|
Loading…
Reference in a new issue