Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override the http.Client for RequestToken and AccessToken #49

Merged
merged 3 commits into from Jun 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions config.go
Expand Up @@ -31,6 +31,8 @@ type Config struct {
Signer Signer
// Noncer creates request nonces (defaults to DefaultNoncer)
Noncer Noncer
// HTTPClient overrides the choice of http.DefaultClient for RequestToken and AccessToken
HTTPClient *http.Client
}

// NewConfig returns a new Config with the given consumer key and secret.
Expand Down Expand Up @@ -71,7 +73,7 @@ func (c *Config) RequestToken() (requestToken, requestSecret string, err error)
if err != nil {
return "", "", err
}
resp, err := http.DefaultClient.Do(req)
resp, err := c.httpClient().Do(req)
if err != nil {
return "", "", err
}
Expand Down Expand Up @@ -148,7 +150,7 @@ func (c *Config) AccessToken(requestToken, requestSecret, verifier string) (acce
if err != nil {
return "", "", err
}
resp, err := http.DefaultClient.Do(req)
resp, err := c.httpClient().Do(req)
if err != nil {
return "", "", err
}
Expand All @@ -173,3 +175,10 @@ func (c *Config) AccessToken(requestToken, requestSecret, verifier string) (acce
}
return accessToken, accessSecret, nil
}

func (c *Config) httpClient() *http.Client {
if c.HTTPClient != nil {
return c.HTTPClient
}
return http.DefaultClient
}