Skip to content

Commit

Permalink
Improve OAuth2 user agent handling (prometheus#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 and radek-ryckowski committed May 22, 2023
1 parent aef35f1 commit 3310674
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions config/http_config.go
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 3310674

Please sign in to comment.