From c2ac2e3055db17afbdd4b86462ff136b718e1454 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 1 Oct 2017 08:59:49 -0700 Subject: [PATCH] tun2: read entire response body --- internal/tun2/connection.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/tun2/connection.go b/internal/tun2/connection.go index ae2d646..9db2195 100644 --- a/internal/tun2/connection.go +++ b/internal/tun2/connection.go @@ -2,7 +2,9 @@ package tun2 import ( "bufio" + "bytes" "context" + "io/ioutil" "net" "net/http" "time" @@ -138,6 +140,15 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) { if err != nil { return nil, errors.Wrap(err, ErrCantReadResponse.Error()) } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrap(err, "can't read response body") + } + + resp.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + resp.ContentLength = int64(len(body)) return resp, nil }