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 }