add curl button
This commit is contained in:
parent
bdaa96ef56
commit
f7de340a06
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 Fabricio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -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/V2mEUfZ.png)
|
||||
![dashboard](https://i.imgur.com/YTukk5J.png)
|
||||
|
||||
|
||||
## Building
|
||||
|
|
|
@ -38,6 +38,7 @@ type CaptureMetadata struct {
|
|||
type CaptureDump struct {
|
||||
Request string `json:"request"`
|
||||
Response string `json:"response"`
|
||||
Curl string `json:"curl"`
|
||||
}
|
||||
|
||||
func (c *Capture) Metadata() CaptureMetadata {
|
||||
|
|
15
dashboard.go
15
dashboard.go
|
@ -193,6 +193,7 @@ 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>
|
||||
</div>
|
||||
<div class="req-inner">
|
||||
<pre>{{request}}</pre>
|
||||
|
@ -225,6 +226,7 @@ const dashboardHTML = `
|
|||
$http.get(path).then(r => {
|
||||
$scope.request = r.data.request;
|
||||
$scope.response = r.data.response;
|
||||
$scope.curl = r.data.curl;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -252,6 +254,19 @@ const dashboardHTML = `
|
|||
return $scope[name].indexOf('Content-Type: application/json') != -1;
|
||||
}
|
||||
|
||||
$scope.canGenerateCurl = () => {
|
||||
return $scope['request'] != null;
|
||||
}
|
||||
|
||||
$scope.generateCurl = () => {
|
||||
let e = document.createElement('textarea');
|
||||
e.value = $scope.curl;
|
||||
document.body.appendChild(e);
|
||||
e.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(e);
|
||||
}
|
||||
|
||||
$scope.prettifyBody = key => {
|
||||
let regex = /\n([\{\[](.*\s*)*[\}\]])/;
|
||||
let data = $scope[key];
|
||||
|
|
1
go.mod
1
go.mod
|
@ -4,4 +4,5 @@ require (
|
|||
github.com/googollee/go-engine.io v0.0.0-20180829091931-e2f255711dcb // indirect
|
||||
github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49
|
||||
github.com/gorilla/websocket v1.4.0 // indirect
|
||||
github.com/ofabricio/curl v0.1.0
|
||||
)
|
||||
|
|
2
go.sum
2
go.sum
|
@ -4,3 +4,5 @@ github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49 h1:vKXGRzlh
|
|||
github.com/googollee/go-socket.io v0.0.0-20181101151912-c8aeb1ed9b49/go.mod h1:ftBGBMhSYToR5oV4ImIPKvAIsNaTkLC+tTvoNafqxlQ=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/ofabricio/curl v0.1.0 h1:ntXuBULZLQmCdAMxZNXzse069DbAKb/Flxe/2uuZuNk=
|
||||
github.com/ofabricio/curl v0.1.0/go.mod h1:RtLkZIOgxjm+l0jdj04lrETzu8u5SmPPdLyGAuC4ukg=
|
||||
|
|
7
main.go
7
main.go
|
@ -15,6 +15,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/googollee/go-socket.io"
|
||||
"github.com/ofabricio/curl"
|
||||
)
|
||||
|
||||
var dashboardSocket socketio.Socket
|
||||
|
@ -156,7 +157,11 @@ func dump(c *Capture) CaptureDump {
|
|||
if err != nil {
|
||||
fmt.Printf("could not dump response: %v\n", err)
|
||||
}
|
||||
return CaptureDump{Request: string(reqDump), Response: string(resDump)}
|
||||
strcurl, err := curl.New(c.Req)
|
||||
if err != nil {
|
||||
fmt.Printf("could not convert request to curl: %v\n", err)
|
||||
}
|
||||
return CaptureDump{Request: string(reqDump), Response: string(resDump), Curl: strcurl}
|
||||
}
|
||||
|
||||
func dumpRequest(req *http.Request) ([]byte, error) {
|
||||
|
|
Loading…
Reference in New Issue