diff --git a/proxy/flow.go b/proxy/flow.go index 2bec3b6..2c09c87 100644 --- a/proxy/flow.go +++ b/proxy/flow.go @@ -3,6 +3,7 @@ package proxy import ( "encoding/json" "errors" + "io" "net/http" "net/url" @@ -96,6 +97,7 @@ type Response struct { StatusCode int `json:"statusCode"` Header http.Header `json:"header"` Body []byte `json:"-"` + BodyReader io.Reader decodedBody []byte decoded bool // decoded reports whether the response was sent compressed but was decoded to decodedBody. diff --git a/proxy/proxy.go b/proxy/proxy.go index 88d87a4..8776329 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -131,10 +131,19 @@ func (proxy *Proxy) ServeHTTP(res http.ResponseWriter, req *http.Request) { if err != nil { logErr(log, err) } - } else if response.Body != nil && len(response.Body) > 0 { - _, err := res.Write(response.Body) - if err != nil { - logErr(log, err) + } + if response.Body != nil { + if response.BodyReader != nil { + _, err := io.Copy(res, response.BodyReader) + if err != nil { + logErr(log, err) + } + } + if len(response.Body) > 0 { + _, err := res.Write(response.Body) + if err != nil { + logErr(log, err) + } } } }