Skip to content

Commit

Permalink
Improve OAuth2 user agent handling (#391)
Browse files Browse the repository at this point in the history
Instead of relying on the User Agent in the configuration, take the User
Agent of the original request. This enables compatibility with existing
user agents.

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
  • Loading branch information
roidelapluie authored Jul 14, 2022
1 parent c5e1b60 commit 49b3603
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,14 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
rt = NewBasicAuthRoundTripper(cfg.BasicAuth.Username, cfg.BasicAuth.Password, cfg.BasicAuth.PasswordFile, rt)
}

if cfg.OAuth2 != nil {
rt = NewOAuth2RoundTripper(cfg.OAuth2, rt, &opts)
}

if opts.userAgent != "" {
rt = NewUserAgentRoundTripper(opts.userAgent, rt)
}

if cfg.OAuth2 != nil {
rt = NewOAuth2RoundTripper(cfg.OAuth2, rt, &opts)
}
// Return a new configured RoundTripper.
return rt, nil
}
Expand Down Expand Up @@ -701,8 +702,8 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
}
}

if rt.opts.userAgent != "" {
t = NewUserAgentRoundTripper(rt.opts.userAgent, t)
if ua := req.UserAgent(); ua != "" {
t = NewUserAgentRoundTripper(ua, t)
}

client := &http.Client{Transport: t}
Expand Down

0 comments on commit 49b3603

Please sign in to comment.