-
Notifications
You must be signed in to change notification settings - Fork 27
Avoid using/changing http.DefaultClient #236
Copy link
Copy link
Closed
stackitcloud/stackit-sdk-generator
#56Labels
bugSomething isn't workingSomething isn't working
Description
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.
stackit-sdk-go/services/serviceaccount/client.go
Lines 74 to 83 in 868d87e
| 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working