aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go
diff options
context:
space:
mode:
authorRadek Simko <radek.simko@gmail.com>2017-08-14 16:10:17 +0200
committerGitHub <noreply@github.com>2017-08-14 16:10:17 +0200
commit00a66330be57dc8d7f987b4235d65d372f6b471f (patch)
tree864f925049d422033dd25a73bafce32b361c8827 /vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go
parentb6a7c48445fdb87dcae46906aa7e9349209d8bb5 (diff)
parentc680a8e1622ed0f18751d9d167c836ee24f5e897 (diff)
downloadterraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.tar.gz
terraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.tar.zst
terraform-provider-statuscake-00a66330be57dc8d7f987b4235d65d372f6b471f.zip
Merge pull request #3 from terraform-providers/vendor-tf-0.10
vendor: github.com/hashicorp/terraform/...@v0.10.0
Diffstat (limited to 'vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go')
-rw-r--r--vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go b/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go
new file mode 100644
index 0000000..7d8a57c
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go
@@ -0,0 +1,56 @@
1package cleanhttp
2
3import (
4 "net"
5 "net/http"
6 "runtime"
7 "time"
8)
9
10// DefaultTransport returns a new http.Transport with similar default values to
11// http.DefaultTransport, but with idle connections and keepalives disabled.
12func DefaultTransport() *http.Transport {
13 transport := DefaultPooledTransport()
14 transport.DisableKeepAlives = true
15 transport.MaxIdleConnsPerHost = -1
16 return transport
17}
18
19// DefaultPooledTransport returns a new http.Transport with similar default
20// values to http.DefaultTransport. Do not use this for transient transports as
21// it can leak file descriptors over time. Only use this for transports that
22// will be re-used for the same host(s).
23func DefaultPooledTransport() *http.Transport {
24 transport := &http.Transport{
25 Proxy: http.ProxyFromEnvironment,
26 DialContext: (&net.Dialer{
27 Timeout: 30 * time.Second,
28 KeepAlive: 30 * time.Second,
29 }).DialContext,
30 MaxIdleConns: 100,
31 IdleConnTimeout: 90 * time.Second,
32 TLSHandshakeTimeout: 10 * time.Second,
33 ExpectContinueTimeout: 1 * time.Second,
34 MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
35 }
36 return transport
37}
38
39// DefaultClient returns a new http.Client with similar default values to
40// http.Client, but with a non-shared Transport, idle connections disabled, and
41// keepalives disabled.
42func DefaultClient() *http.Client {
43 return &http.Client{
44 Transport: DefaultTransport(),
45 }
46}
47
48// DefaultPooledClient returns a new http.Client with similar default values to
49// http.Client, but with a shared Transport. Do not use this function for
50// transient clients as it can leak file descriptors over time. Only use this
51// for clients that will be re-used for the same host(s).
52func DefaultPooledClient() *http.Client {
53 return &http.Client{
54 Transport: DefaultPooledTransport(),
55 }
56}