forked from bogdanfinn/tls-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_options.go
86 lines (72 loc) · 2.05 KB
/
client_options.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package tls_client
import (
"time"
http "github.com/bogdanfinn/fhttp"
)
type HttpClientOption func(config *httpClientConfig)
type TransportOptions struct {
DisableKeepAlives bool
DisableCompression bool
MaxIdleConns int
MaxIdleConnsPerHost int
MaxConnsPerHost int
MaxResponseHeaderBytes int64 // Zero means to use a default limit.
WriteBufferSize int // If zero, a default (currently 4KB) is used.
ReadBufferSize int // If zero, a default (currently 4KB) is used.
}
type httpClientConfig struct {
debug bool
followRedirects bool
insecureSkipVerify bool
proxyUrl string
serverNameOverwrite string
transportOptions *TransportOptions
cookieJar http.CookieJar
clientProfile ClientProfile
timeout time.Duration
}
func WithProxyUrl(proxyUrl string) HttpClientOption {
return func(config *httpClientConfig) {
config.proxyUrl = proxyUrl
}
}
func WithCookieJar(jar http.CookieJar) HttpClientOption {
return func(config *httpClientConfig) {
config.cookieJar = jar
}
}
func WithTimeout(timeout int) HttpClientOption {
return func(config *httpClientConfig) {
config.timeout = time.Second * time.Duration(timeout)
}
}
func WithNotFollowRedirects() HttpClientOption {
return func(config *httpClientConfig) {
config.followRedirects = false
}
}
func WithDebug() HttpClientOption {
return func(config *httpClientConfig) {
config.debug = true
}
}
func WithTransportOptions(transportOptions *TransportOptions) HttpClientOption {
return func(config *httpClientConfig) {
config.transportOptions = transportOptions
}
}
func WithInsecureSkipVerify() HttpClientOption {
return func(config *httpClientConfig) {
config.insecureSkipVerify = true
}
}
func WithClientProfile(clientProfile ClientProfile) HttpClientOption {
return func(config *httpClientConfig) {
config.clientProfile = clientProfile
}
}
func WithServerNameOverwrite(serverName string) HttpClientOption {
return func(config *httpClientConfig) {
config.serverNameOverwrite = serverName
}
}