aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection_streams_controller.go8
-rw-r--r--utils.go41
2 files changed, 48 insertions, 1 deletions
diff --git a/connection_streams_controller.go b/connection_streams_controller.go
index 251e842..000e3d4 100644
--- a/connection_streams_controller.go
+++ b/connection_streams_controller.go
@@ -110,9 +110,15 @@ func (csc ConnectionStreamsController) GetConnectionPayload(c context.Context, c
}
size := uint64(end - start)
+ content := DecodeBytes(serverStream.Payload[start:end], format.Format)
+ // check if is encoded
+ if format.Format == "default" {
+ content = DecodeHttpResponse(content)
+ }
+
payload = Payload{
FromClient: false,
- Content: DecodeBytes(serverStream.Payload[start:end], format.Format),
+ Content: content,
Index: start,
Timestamp: serverStream.BlocksTimestamps[serverBlocksIndex],
IsRetransmitted: serverStream.BlocksLoss[serverBlocksIndex],
diff --git a/utils.go b/utils.go
index a14fdca..e222b17 100644
--- a/utils.go
+++ b/utils.go
@@ -13,6 +13,12 @@ import (
"net"
"os"
"time"
+ //"net/textproto"
+ "net/http"
+ "bufio"
+ "strings"
+ "io/ioutil"
+ "compress/gzip"
)
func Sha256Sum(fileName string) (string, error) {
@@ -108,6 +114,41 @@ func DecodeBytes(buffer []byte, format string) string {
}
}
+func DecodeHttpResponse(raw string) string {
+ var header string
+ trailer := "\n"
+ reader := bufio.NewReader(strings.NewReader(raw))
+ resp,err := http.ReadResponse(reader, &http.Request{})
+ if err != nil{
+ log.Info("Reading response: ",resp)
+ return raw + trailer
+ }
+
+ defer resp.Body.Close()
+
+ if resp.StatusCode == http.StatusOK {
+ var bodyReader io.ReadCloser
+ switch resp.Header.Get("Content-Encoding") {
+ case "gzip":
+ bodyReader, err = gzip.NewReader(resp.Body)
+ if err != nil {
+ log.Error("Gunzipping body: ",err)
+ }
+ header = "\n[==== GUNZIPPED ====]\n"
+ trailer = "\n[===================]\n"
+ defer bodyReader.Close()
+ default:
+ bodyReader = resp.Body
+ }
+ body, err := ioutil.ReadAll(bodyReader)
+ if err != nil{
+ log.Error("Reading body: ",err)
+ }
+ return raw + header + string(body) + trailer
+ }
+ return raw + trailer
+}
+
func CopyFile(dst, src string) error {
in, err := os.Open(src)
if err != nil {