httputil.go 592 B

12345678910111213141516171819202122
  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. // borrowed from golang/net/context/ctxhttp/cancelreq.go
  5. // Package httputil provides HTTP utility functions.
  6. package httputil
  7. import (
  8. "io"
  9. "io/ioutil"
  10. "net/http"
  11. )
  12. // GracefulClose drains http.Response.Body until it hits EOF
  13. // and closes it. This prevents TCP/TLS connections from closing,
  14. // therefore available for reuse.
  15. func GracefulClose(resp *http.Response) {
  16. io.Copy(ioutil.Discard, resp.Body)
  17. resp.Body.Close()
  18. }