When the user of the library does not provide a custom cient,
http.DefaultClient is used, and a custom RoundTripper is set in order to
implement authentication / retries, e.g.
|
if cfg.HTTPClient == nil { |
|
cfg.HTTPClient = http.DefaultClient |
|
} |
|
|
|
authRoundTripper, err := auth.SetupAuth(cfg) |
|
if err != nil { |
|
return nil, fmt.Errorf("setting up authentication: %w", err) |
|
} |
|
|
|
cfg.HTTPClient.Transport = authRoundTripper |
This can have unintended consequences and should be avoided in my opinion. Now,
every time I (or another package) uses the default client, it behaves
differently than expected.
I'd suggest to instead create a new client: cfg.HTTPClient = &http.Client{}.
This change would need to be done for every service.
When the user of the library does not provide a custom cient,
http.DefaultClientis used, and a custom RoundTripper is set in order toimplement authentication / retries, e.g.
stackit-sdk-go/services/serviceaccount/client.go
Lines 74 to 83 in 868d87e
This can have unintended consequences and should be avoided in my opinion. Now,
every time I (or another package) uses the default client, it behaves
differently than expected.
I'd suggest to instead create a new client:
cfg.HTTPClient = &http.Client{}.This change would need to be done for every service.