Skip to content

Commit

Permalink
Merge pull request #780 from CircleCI-Public/nr/feat/EXT-307/fix-cust…
Browse files Browse the repository at this point in the history
…om-certs-w-tls

[EXT-307] Clone default transport to ignore bad certs & update GraphQL client to use custom HTTP Client
  • Loading branch information
nramabad authored Oct 3, 2022
2 parents 79819a8 + 2fa2d3c commit d66718f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion api/graphql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Client struct {
// NewClient returns a reference to a Client.
func NewClient(httpClient *http.Client, host, endpoint, token string, debug bool) *Client {
return &Client{
httpClient: http.DefaultClient,
httpClient: httpClient,
Endpoint: endpoint,
Host: host,
Token: token,
Expand Down
18 changes: 10 additions & 8 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,17 @@ func (cfg *Config) WithHTTPClient() error {
tlsConfig.RootCAs = pool
}

// clone default http transport to retain default transport config values
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.ExpectContinueTimeout = time.Second
customTransport.IdleConnTimeout = 90 * time.Second
customTransport.MaxIdleConns = 10
customTransport.TLSHandshakeTimeout = 10 * time.Second
customTransport.TLSClientConfig = tlsConfig

cfg.HTTPClient = &http.Client{
Timeout: 60 * time.Second,
Transport: &http.Transport{
ExpectContinueTimeout: 1 * time.Second,
IdleConnTimeout: 90 * time.Second,
MaxIdleConns: 10,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: tlsConfig,
},
Timeout: 60 * time.Second,
Transport: customTransport,
}

return nil
Expand Down

0 comments on commit d66718f

Please sign in to comment.