| 1 |
// Copyright 2015 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// borrowed from golang/net/context/ctxhttp/cancelreq.go |
| 6 |
|
| 7 |
// Package httputil provides HTTP utility functions. |
| 8 |
package httputil |
| 9 |
|
| 10 |
import ( |
| 11 |
"io" |
| 12 |
"io/ioutil" |
| 13 |
"net/http" |
| 14 |
) |
| 15 |
|
| 16 |
// GracefulClose drains http.Response.Body until it hits EOF |
| 17 |
// and closes it. This prevents TCP/TLS connections from closing, |
| 18 |
// therefore available for reuse. |
| 19 |
func GracefulClose(resp *http.Response) { |
| 20 |
io.Copy(ioutil.Discard, resp.Body) |
| 21 |
resp.Body.Close() |
| 22 |
} |