Revert "tun2: put content length in response"

This reverts commit c3b786b992.
This commit is contained in:
Cadey Ratio 2017-10-07 08:46:32 -07:00
parent 8e94968e17
commit d257215ff4
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
1 changed files with 7 additions and 5 deletions

View File

@ -2,10 +2,11 @@ package tun2
import ( import (
"bufio" "bufio"
"bytes"
"context" "context"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"strconv"
"time" "time"
"github.com/Xe/ln" "github.com/Xe/ln"
@ -126,6 +127,7 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) {
if err != nil { if err != nil {
return nil, errors.Wrap(err, ErrCantOpenSessionStream.Error()) return nil, errors.Wrap(err, ErrCantOpenSessionStream.Error())
} }
defer stream.Close()
err = req.Write(stream) err = req.Write(stream)
if err != nil { if err != nil {
@ -140,13 +142,13 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
cl := resp.Header.Get("Content-Length") body, err := ioutil.ReadAll(resp.Body)
asInt, err := strconv.Atoi(cl)
if err != nil { if err != nil {
return nil, err return nil, errors.Wrap(err, "can't read response body")
} }
resp.ContentLength = int64(asInt) resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
resp.ContentLength = int64(len(body))
return resp, nil return resp, nil
} }