tun2: put content length in response
This commit is contained in:
parent
73f278aed2
commit
c3b786b992
|
@ -2,11 +2,10 @@ 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"
|
||||||
|
@ -127,7 +126,6 @@ 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 {
|
||||||
|
@ -142,13 +140,13 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
cl := resp.Header.Get("Content-Length")
|
||||||
|
asInt, err := strconv.Atoi(cl)
|
||||||
if err != nil {
|
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(asInt)
|
||||||
resp.ContentLength = int64(len(body))
|
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue