1919package api
2020
2121import (
22+ "context"
2223 "fmt"
2324 "math/rand"
25+ "net"
2426 "net/http"
2527 "net/url"
2628 "strconv"
@@ -91,6 +93,19 @@ func NewClient(account string, opts ...Option) (*Client, error) {
9193 return nil , err
9294 }
9395
96+ defaultTransport := & http.Transport {
97+ Proxy : http .ProxyFromEnvironment ,
98+ DialContext : defaultTransportDialContext (& net.Dialer {
99+ Timeout : 30 * time .Second ,
100+ KeepAlive : 30 * time .Second ,
101+ }),
102+ ForceAttemptHTTP2 : true ,
103+ MaxIdleConns : 100 ,
104+ IdleConnTimeout : 90 * time .Second ,
105+ TLSHandshakeTimeout : defaultTLSTimeout ,
106+ ExpectContinueTimeout : 1 * time .Second ,
107+ }
108+
94109 c := & Client {
95110 id : newID (),
96111 account : account ,
@@ -103,7 +118,7 @@ func NewClient(account string, opts ...Option) (*Client, error) {
103118 expiration : DefaultTokenExpiryTime ,
104119 },
105120 c : & http.Client {Timeout : defaultTimeout ,
106- Transport : & http. Transport { TLSHandshakeTimeout : defaultTLSTimeout } },
121+ Transport : defaultTransport },
107122 }
108123
109124 c .V2 = NewV2Endpoints (c )
@@ -241,3 +256,7 @@ func newID() string {
241256 seed := rand .New (rand .NewSource (now ))
242257 return strconv .FormatInt (seed .Int63 (), 16 )
243258}
259+
260+ func defaultTransportDialContext (dialer * net.Dialer ) func (context.Context , string , string ) (net.Conn , error ) {
261+ return dialer .DialContext
262+ }
0 commit comments