Skip to content

Commit 49b3603

Browse files
author
Julien Pivotto
authored
Improve OAuth2 user agent handling (#391)
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 <[email protected]>
1 parent c5e1b60 commit 49b3603

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

config/http_config.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,14 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
505505
rt = NewBasicAuthRoundTripper(cfg.BasicAuth.Username, cfg.BasicAuth.Password, cfg.BasicAuth.PasswordFile, rt)
506506
}
507507

508+
if cfg.OAuth2 != nil {
509+
rt = NewOAuth2RoundTripper(cfg.OAuth2, rt, &opts)
510+
}
511+
508512
if opts.userAgent != "" {
509513
rt = NewUserAgentRoundTripper(opts.userAgent, rt)
510514
}
511515

512-
if cfg.OAuth2 != nil {
513-
rt = NewOAuth2RoundTripper(cfg.OAuth2, rt, &opts)
514-
}
515516
// Return a new configured RoundTripper.
516517
return rt, nil
517518
}
@@ -701,8 +702,8 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
701702
}
702703
}
703704

704-
if rt.opts.userAgent != "" {
705-
t = NewUserAgentRoundTripper(rt.opts.userAgent, t)
705+
if ua := req.UserAgent(); ua != "" {
706+
t = NewUserAgentRoundTripper(ua, t)
706707
}
707708

708709
client := &http.Client{Transport: t}

0 commit comments

Comments
 (0)