Skip to content

Avoid using/changing http.DefaultClient #236

Closed
stackitcloud/stackit-sdk-generator
#56

Description

@maboehm

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.

Activity

  1. joaopalet commented on Jan 10, 2024

    @joaopalet
    Contributor

    Hi,

    Thank you for opening the issue! We have created a bug ticket for this and will work on it soon

  2. hcsa73 commented on Jan 24, 2024

    @hcsa73
    Contributor

    Fixed in the most recent release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions