mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: drain http.Response.Body before closing
This commit is contained in:
@@ -7,7 +7,11 @@
|
||||
// Package httputil provides HTTP utility functions.
|
||||
package httputil
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RequestCanceler(rt http.RoundTripper, req *http.Request) func() {
|
||||
ch := make(chan struct{})
|
||||
@@ -17,3 +21,11 @@ func RequestCanceler(rt http.RoundTripper, req *http.Request) func() {
|
||||
close(ch)
|
||||
}
|
||||
}
|
||||
|
||||
// GracefulClose drains http.Response.Body until it hits EOF
|
||||
// and closes it. This prevents TCP/TLS connections from closing,
|
||||
// therefore available for reuse.
|
||||
func GracefulClose(resp *http.Response) {
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user