Skip to content
Permalink
Browse files

Base64 encode request/response for socket transfer

  • Loading branch information
antoniomika committed Dec 24, 2019
1 parent f26fde6 commit 8466ab5f3f23553c893900c7263060f18dee35e3
Showing with 7 additions and 6 deletions.
  1. +3 −2 http.go
  2. +4 −4 templates/console.tmpl
@@ -4,6 +4,7 @@ import (
"bytes"
"compress/gzip"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
@@ -222,11 +223,11 @@ func startHTTPHandler(state *State) {
"requestMethod": c.Request.Method,
"requestUrl": c.Request.URL,
"requestHeaders": requestHeaders,
"requestBody": string(reqBody),
"requestBody": base64.StdEncoding.EncodeToString(reqBody),
"responseHeaders": response.Header,
"responseCode": response.StatusCode,
"responseStatus": response.Status,
"responseBody": string(resBody),
"responseBody": base64.StdEncoding.EncodeToString(resBody),
})

if err != nil {
@@ -79,11 +79,11 @@

if ("Content-Type" in requestData.requestHeaders && requestData.requestHeaders["Content-Type"][0] == "application/json") {
$("#requestBody").html(`
<pre><code>${JSON.stringify(JSON.parse(requestData.requestBody), null, 4)}</code></pre>
<pre><code>${JSON.stringify(JSON.parse(atob(requestData.requestBody)), null, 4)}</code></pre>
`);
} else {
$("#requestBody").html(`
<pre><code>${requestData.requestBody}</code></pre>
<pre><code>${atob(requestData.requestBody)}</code></pre>
`);
}

@@ -93,11 +93,11 @@

if ("Content-Type" in requestData.responseHeaders && requestData.responseHeaders["Content-Type"][0] == "application/json") {
$("#responseBody").html(`
<pre><code>${JSON.stringify(JSON.parse(requestData.responseBody), null, 4)}</code></pre>
<pre><code>${JSON.stringify(JSON.parse(atob(requestData.responseBody)), null, 4)}</code></pre>
`);
} else {
$("#responseBody").html(`
<pre><code>${requestData.responseBody}</code></pre>
<pre><code>${atob(requestData.responseBody)}</code></pre>
`);
}

0 comments on commit 8466ab5

Please sign in to comment.
You can’t perform that action at this time.