Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
Add show curl command
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Apr 19, 2017
1 parent 23bf9ac commit ce45e7a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
/.boast.json
.DS_Store
/web/bindata_assetfs.go
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tools :
go get github.com/laher/goxc

build-fe :
cd frontend; npm run build; cd -
cd frontend; npm run build

build : tools
go-bindata-assetfs -pkg web assets/... ; mv bindata_assetfs.go web
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Boast

Install the boast package:

`go get https://github.com/dcb9/boast`
`go get github.com/dcb9/boast`

After installing, modify your server file

Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Boast

安装 boast 包

`go get https://github.com/dcb9/boast`
`go get github.com/dcb9/boast`

然后修改 server 程序

Expand Down
10 changes: 10 additions & 0 deletions frontend/src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<div class="col-4">Request</div>
<div class="col-8"><button class="btn replay" v-on:click="replay(cts.ID)">Replay</button></div>
</h3>
<div>
<p><a v-on:click="doDownloadCurl()" href="javascript:;">show cURL command</a></p>
<span v-if="downloadCurl"><a target="_blank" href="https://www.getpostman.com/docs/importing_curl">Tips</a></span>
<div v-if="downloadCurl" style="background-color: #c2c2c2; padding: 5px 5px 0; word-break: break-all"><pre><code style="white-space:normal;">{{ cts.Req.CurlCommand | base64Decode }}</code></pre></div>
</div>
<div>
<pre><code>{{ cts.Req.RawText | base64Decode }}</code></pre>
</div>
Expand Down Expand Up @@ -121,6 +126,7 @@
cts: currentTransaction,
wsConnected: false,
wsConn: {},
downloadCurl: false,
}
},
created: function() {
Expand Down Expand Up @@ -164,9 +170,13 @@
t.Selected = true;
this.cts = t;
this.downloadCurl = false;
},
replay: function(id) {
this.wsConn.send(JSON.stringify({Action: "replay", ID: id}))
},
doDownloadCurl: function() {
this.downloadCurl = !this.downloadCurl;
}
},
filters: {
Expand Down
1 change: 1 addition & 0 deletions transaction/reverseProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error

t := Ts{
ID: id,
RawReq: req,
Req: tsReq,
Resp: NewResp(resp),
ClientAddr: req.RemoteAddr,
Expand Down
13 changes: 7 additions & 6 deletions transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ type Resp struct {
}

type Ts struct {
ID uuid.UUID `json:"ID"`
Req *Req `json:"Req"`
Resp *Resp `json:"Resp"`
ClientAddr string `json:"ClientAddr"`
BeginAt time.Time `json:"BeginAt"`
EndAt time.Time `json:"EndAt"`
ID uuid.UUID `json:"ID"`
RawReq *http.Request `json:"-"`
Req *Req `json:"Req"`
Resp *Resp `json:"Resp"`
ClientAddr string `json:"ClientAddr"`
BeginAt time.Time `json:"BeginAt"`
EndAt time.Time `json:"EndAt"`
}

func NewReq(req *http.Request) *Req {
Expand Down
102 changes: 51 additions & 51 deletions web/bindata_assetfs.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions web/ws/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

type Request struct {
Method string `json:"Method"`
Path string `json:"Path"`
RawText string `json:"RawText"`
Method string `json:"Method"`
Path string `json:"Path"`
RawText string `json:"RawText"`
CurlCommand string `json:"CurlCommand"`
}

type Response struct {
Expand Down
9 changes: 6 additions & 3 deletions web/ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/dcb9/boast/transaction"
"github.com/gorilla/websocket"
"github.com/moul/http2curl"
)

var tsHub = transaction.TsHub
Expand Down Expand Up @@ -88,12 +89,14 @@ func (c *Client) sendTss(tss []*transaction.Ts) error {
)
}

curlCommand, _ := http2curl.GetCurlCommand(ts.RawReq)
t := Transaction{
ID: ts.ID,
Request: Request{
Method: ts.Req.Method,
Path: ts.Req.URL.Path,
RawText: base64.StdEncoding.EncodeToString([]byte(rawReq)),
Method: ts.Req.Method,
Path: ts.Req.URL.Path,
RawText: base64.StdEncoding.EncodeToString([]byte(rawReq)),
CurlCommand: base64.StdEncoding.EncodeToString([]byte(curlCommand.String())),
},
Response: Response{
Status: ts.Resp.Status,
Expand Down

0 comments on commit ce45e7a

Please sign in to comment.