blob: 09f44e7c71d9a8dd1d26a68cfcf0df53792c1357 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001// 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.
8package httputil
9
10import (
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.
19func GracefulClose(resp *http.Response) {
20 io.Copy(ioutil.Discard, resp.Body)
21 resp.Body.Close()
22}