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

Commit

Permalink
show response body in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Jun 14, 2017
1 parent ce45e7a commit 4550e90
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 85 deletions.
14 changes: 10 additions & 4 deletions frontend/src/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<div>
<pre><code>{{ cts.Resp.RawText | base64Decode }}</code></pre>
</div>
<p><a :href="this.responseBodyURL" target="_blank">SHOW RESPONSE IN A NEW TAB</a></p>
</div>
</div>
</div>
Expand Down Expand Up @@ -127,18 +128,23 @@
wsConnected: false,
wsConn: {},
downloadCurl: false,
host: "",
}
},
computed: {
responseBodyURL: function() {
return `//${this.host}/responses/${this.cts.ID}`
},
},
created: function() {
if (this.hasWebSocket) {
var wsHost
if (typeof process.env.WS_HOST == "undefined") {
wsHost = window.location.host
this.host = window.location.host
} else {
wsHost = process.env.WS_HOST
this.host = process.env.WS_HOST
}
var conn = new WebSocket("ws://" + wsHost + "/ws");
var conn = new WebSocket(`ws://${this.host}/ws`);
conn.onopen = (evt) => {
console.log("Connection connected")
this.wsConnected = true
Expand Down
154 changes: 77 additions & 77 deletions web/bindata_assetfs.go

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import (
"log"
"net/http"

"fmt"
"github.com/dcb9/boast/config"
"github.com/dcb9/boast/transaction"
"github.com/dcb9/boast/web/ws"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/google/uuid"
"strings"
"io"
"bytes"
)

var wsHub = ws.NewHub()
var tsHub = transaction.TsHub

func Serve() {
go wsHub.Run()
http.Handle("/static/", http.StripPrefix(
"/static/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "assets/static"}),
))

http.HandleFunc("/replay", func(rw http.ResponseWriter, req *http.Request) {
})

http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
tpl, err := Asset("assets/index.html")
if err != nil {
Expand All @@ -38,6 +42,20 @@ func Serve() {
log.Fatal(err)
}
})
http.HandleFunc("/responses/", func(rw http.ResponseWriter, req *http.Request) {
lastSlash := strings.LastIndex(req.URL.Path, "/")
bs := []byte(req.URL.Path)
uuidS := bs[lastSlash+1:]

id, err := uuid.Parse(string(uuidS))
if err != nil {
fmt.Fprint(rw, "Bad Request")
}

resp := tsHub.Transactions[id].Resp
src := bytes.NewReader(resp.Body)
io.Copy(rw, src)
})

http.HandleFunc("/ws", func(rw http.ResponseWriter, req *http.Request) {
ws.Serve(wsHub, rw, req)
Expand Down
18 changes: 17 additions & 1 deletion web/ws/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ws

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/dcb9/boast/transaction"
"github.com/gorilla/websocket"
"github.com/moul/http2curl"
"io/ioutil"
)

var tsHub = transaction.TsHub
Expand Down Expand Up @@ -82,13 +84,27 @@ func (c *Client) sendTss(tss []*transaction.Ts) error {
rawHeaders = append(rawHeaders, key+": "+strings.Join(vals, ",")+"\r\n")
}

contenType := ts.Resp.Header.Get("Content-Type")
var body string
if strings.Contains(contenType, "text") ||
strings.Contains(contenType, "html") ||
strings.Contains(contenType, "xml") ||
strings.Contains(contenType, "json") ||
strings.Contains(contenType, "javascript") {
body = string(ts.Resp.Body)
}

rawResp = fmt.Sprintf(
"%s %s\r\n%s\r\n%s",
ts.Resp.Proto, ts.Resp.Status,
strings.Join(rawHeaders, ""), ts.Resp.Body,
strings.Join(rawHeaders, ""), body,
)
}

reader := bytes.NewReader(ts.Req.Body)
readCloser := ioutil.NopCloser(reader)
ts.RawReq.Body = readCloser

curlCommand, _ := http2curl.GetCurlCommand(ts.RawReq)
t := Transaction{
ID: ts.ID,
Expand Down

0 comments on commit 4550e90

Please sign in to comment.