diff options
| author | Shulhan <ms@kilabit.info> | 2024-12-12 21:21:55 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-12-28 14:41:07 +0700 |
| commit | 7979b504cdf442e13db6bcabbdb0375a60d022f0 (patch) | |
| tree | 262b7502b971f96e5b00903dd516f7a38aaad719 /lib/http | |
| parent | d8a4dae6ad9672285dc007e7c52c63026278d00a (diff) | |
| download | pakakeh.go-7979b504cdf442e13db6bcabbdb0375a60d022f0.tar.xz | |
lib/http: simplify setting Client Transport
While at it, set the ExpectContinueTimeout using the Timeout from
ClientOptions.
Diffstat (limited to 'lib/http')
| -rw-r--r-- | lib/http/client.go | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/lib/http/client.go b/lib/http/client.go index 2dad2159..92ec4372 100644 --- a/lib/http/client.go +++ b/lib/http/client.go @@ -51,7 +51,12 @@ type Client struct { func NewClient(opts ClientOptions) (client *Client) { opts.init() - httpTransport := &http.Transport{ + client = &Client{ + opts: opts, + Client: &http.Client{}, + } + + client.Client.Transport = &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: opts.Timeout, @@ -60,19 +65,11 @@ func NewClient(opts ClientOptions) (client *Client) { MaxIdleConns: 1, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: opts.Timeout, - ExpectContinueTimeout: 1 * time.Second, - } - - client = &Client{ - opts: opts, - Client: &http.Client{}, - } - if opts.AllowInsecure { - httpTransport.TLSClientConfig = &tls.Config{ - InsecureSkipVerify: opts.AllowInsecure, //nolint:gosec - } + ExpectContinueTimeout: opts.Timeout, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: opts.AllowInsecure, + }, } - client.Client.Transport = httpTransport client.setUserAgent() |
