diff --git a/core/corehttp/proxy.go b/core/corehttp/proxy.go index 7a9946ff45a4..98e887a4f828 100644 --- a/core/corehttp/proxy.go +++ b/core/corehttp/proxy.go @@ -33,7 +33,7 @@ func ProxyOption() ServeOption { handleError(w, msg, err, 500) return } - + //send proxy request and response to client newReverseHttpProxy(parsedRequest, &stream).ServeHTTP(w, request) }) return mux, nil @@ -86,7 +86,18 @@ type roundTripper struct { } func (self *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - req.Write(*self.stream) + + sendRequest := func() { + err := req.Write(*self.stream) + if err != nil { + (*(self.stream)).Close() + } + if req.Body != nil { + req.Body.Close() + } + } + //send request while reading response + go sendRequest() s := bufio.NewReader(*self.stream) return http.ReadResponse(s, req) }