-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
56 lines (48 loc) · 1.52 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package vault_plugin_kv_rotate
import (
"errors"
"net/http"
"time"
)
// httpClient creates an object storing
// the client.
type httpClient struct {
*http.Client
}
// newClient creates a new client to access HashiCups
// and exposes it for any secrets or roles to use.
func newClient(config *httpClientConfig) (*httpClient, error) {
if config == nil {
return nil, errors.New("client configuration was nil")
}
if config.MaxIdleConns == 0 {
return nil, errors.New("client MaxIdleConns was not defined")
}
if config.MaxIdleConnsPerHost == 0 {
return nil, errors.New("client MaxIdleConnsPerHost was not defined")
}
if config.MaxIdleConnsPerHost == 0 {
return nil, errors.New("client MaxConnsPerHost was not defined")
}
if config.IdleConnTimeout == 0*time.Second {
return nil, errors.New("client IdleTimeout was not defined")
}
tr := &http.Transport{
//Proxy: http.ProxyFromEnvironment,
//Proxy: http.ProxyURL(someProxyUrl),
MaxIdleConns: config.MaxIdleConns,
MaxIdleConnsPerHost: config.MaxIdleConnsPerHost,
MaxConnsPerHost: config.MaxConnsPerHost,
IdleConnTimeout: config.IdleConnTimeout,
//ResponseHeaderTimeout: , // default unlimited
//ExpectContinueTimeout: , // default unlimited
//WriteBufferSize: , // default 4KB
//ReadBufferSize: , // default 4KB
}
c := &http.Client{
Transport: tr,
CheckRedirect: nil, // nil == use the default: follow up to 10 redirects
//Timeout: , // global limit for connecting, redirecting, and reading response body.
}
return &httpClient{c}, nil
}