diff --git a/response.go b/response.go index faf7244..8de1aa1 100644 --- a/response.go +++ b/response.go @@ -10,7 +10,6 @@ import ( "io" "net/http" "os" - "runtime" "gopkg.in/h2non/gentleman.v1/context" "gopkg.in/h2non/gentleman.v1/utils" @@ -71,9 +70,6 @@ func buildResponse(ctx *context.Context) (*Response, error) { Cookies: resp.Cookies(), buffer: bytes.NewBuffer([]byte{}), } - if !isChunkedResponse(resp) { - EnsureResponseFinalized(res) - } return res, res.Error } @@ -228,14 +224,6 @@ func (r *Response) getInternalReader() io.Reader { return r } -// EnsureResponseFinalized will ensure that when the Response is GCed -// the request body is closed so we aren't leaking fds. -func EnsureResponseFinalized(httpResp *Response) { - runtime.SetFinalizer(&httpResp, func(httpResponseInt **Response) { - (*httpResponseInt).RawResponse.Body.Close() - }) -} - // isChunkedResponse iterates over the response's transfer encodings // and returns either true whether 'chunked' is found, or false, otherwise. func isChunkedResponse(res *http.Response) bool { diff --git a/utils/utils.go b/utils/utils.go index 4f41c2b..c3adad6 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -7,7 +7,6 @@ import ( "io" "io/ioutil" "net/http" - "runtime" "strconv" ) @@ -51,21 +50,3 @@ func (nopCloser) Close() error { return nil } func NopCloser() io.ReadCloser { return nopCloser{bytes.NewBuffer([]byte{})} } - -// EnsureTransporterFinalized will ensure that when the HTTP client is GCed -// the runtime will close the idle connections (so that they won't leak) -// this function was adopted from Hashicorp's go-cleanhttp package. -func EnsureTransporterFinalized(httpTransport *http.Transport) { - runtime.SetFinalizer(&httpTransport, func(transportInt **http.Transport) { - (*transportInt).CloseIdleConnections() - }) -} - -// SetTransportFinalizer sets a finalizer on the transport to ensure that -// idle connections are closed prior to garbage collection; otherwise -// these may leak. -func SetTransportFinalizer(transport *http.Transport) { - runtime.SetFinalizer(&transport, func(t **http.Transport) { - (*t).CloseIdleConnections() - }) -}