Skip to content

Avoid using/changing http.DefaultClient #236

@maboehm

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.

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