internal/tun2: forward stream buffered reader and closer to response bodies
This commit is contained in:
parent
6038f2f151
commit
223b816f88
|
@ -2,8 +2,8 @@ package tun2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -127,7 +127,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 {
|
||||||
|
@ -147,8 +146,17 @@ func (c *Connection) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
return nil, errors.Wrap(err, "can't read response body")
|
return nil, errors.Wrap(err, "can't read response body")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
resp.Body = &mixedReadCloser{
|
||||||
|
Reader: buf,
|
||||||
|
Closer: stream,
|
||||||
|
}
|
||||||
|
|
||||||
resp.ContentLength = int64(len(body))
|
resp.ContentLength = int64(len(body))
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mixedReadCloser struct {
|
||||||
|
io.Reader
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue