-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
82 lines (70 loc) · 2.01 KB
/
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
// SPDX-FileCopyrightText: 2024-Present Datadog, Inc
// SPDX-License-Identifier: Apache-2.0
package httpclient
import (
"context"
"crypto/tls"
"net"
"time"
)
// Option represents http client functional option pattern type.
type Option func(*options)
type options struct {
timeout time.Duration
disableKeepAlives bool
disableRequestFilter bool
disableResponseFilter bool
followRedirect bool
maxRedirectionCount int
tlsConfig *tls.Config
tlsDialContext func(context.Context, string, string) (net.Conn, error)
}
// WithTimeout sets the client timeout.
func WithTimeout(value time.Duration) Option {
return func(o *options) {
o.timeout = value
}
}
// WithDisableKeepAlives disables the keep alive feature.
func WithDisableKeepAlives(value bool) Option {
return func(o *options) {
o.disableKeepAlives = value
}
}
// WithDisableRequestFilter disables the request filtering feature.
func WithDisableRequestFilter(value bool) Option {
return func(o *options) {
o.disableRequestFilter = value
}
}
// WithDisableResponseFilter disables the response filtering feature.
func WithDisableResponseFilter(value bool) Option {
return func(o *options) {
o.disableResponseFilter = value
}
}
// WithFollowRedirect disables the redirection follower feature.
func WithFollowRedirect(value bool) Option {
return func(o *options) {
o.followRedirect = value
}
}
// WithMaxRedirectionCount sets the maximum redirection count before returning
// an error.
func WithMaxRedirectionCount(value int) Option {
return func(o *options) {
o.maxRedirectionCount = value
}
}
// WithTLSClientConfig sets the HTTP client TLS configuration to use for connection.
func WithTLSClientConfig(value *tls.Config) Option {
return func(o *options) {
o.tlsConfig = value
}
}
// WithTLSDialer sets the TLS Dialer function to use to establish the connection.
func WithTLSDialer(dialer func(context.Context, string, string) (net.Conn, error)) Option {
return func(o *options) {
o.tlsDialContext = dialer
}
}