tun2: put content length in response

This commit is contained in:
Cadey Ratio 2017-10-04 13:52:46 -07:00
parent 73f278aed2
commit c3b786b992
1 changed files with 5 additions and 7 deletions

View File

@ -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
}