From c3b786b992971ba9f22a9d7d6b3f00d3e86b36d2 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 4 Oct 2017 13:52:46 -0700 Subject: [PATCH] tun2: put content length in response --- internal/tun2/connection.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/internal/tun2/connection.go b/internal/tun2/connection.go index 9db2195..b68cfe4 100644 --- a/internal/tun2/connection.go +++ b/internal/tun2/connection.go @@ -2,11 +2,10 @@ package tun2 import ( "bufio" - "bytes" "context" - "io/ioutil" "net" "net/http" + "strconv" "time" "github.com/Xe/ln" @@ -127,7 +126,6 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) { if err != nil { return nil, errors.Wrap(err, ErrCantOpenSessionStream.Error()) } - defer stream.Close() err = req.Write(stream) if err != nil { @@ -142,13 +140,13 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + cl := resp.Header.Get("Content-Length") + asInt, err := strconv.Atoi(cl) if err != nil { - return nil, errors.Wrap(err, "can't read response body") + return nil, err } - resp.Body = ioutil.NopCloser(bytes.NewBuffer(body)) - resp.ContentLength = int64(len(body)) + resp.ContentLength = int64(asInt) return resp, nil }