Skip to content

Commit 2a57d23

Browse files
Julien Pivottoradek-ryckowski
authored andcommitted
Improve OAuth2 user agent handling (prometheus#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 fd62d38 commit 2a57d23

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

config/http_config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
653653
rt = NewBasicAuthRoundTripper(usernameSecret, passwordSecret, rt)
654654
}
655655

656+
if cfg.OAuth2 != nil {
657+
rt = NewOAuth2RoundTripper(cfg.OAuth2, rt, &opts)
658+
}
659+
656660
if opts.userAgent != "" {
657661
rt = NewUserAgentRoundTripper(opts.userAgent, rt)
658662
}
@@ -676,7 +680,6 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
676680
if opts.host != "" {
677681
rt = NewHostRoundTripper(opts.host, rt)
678682
}
679-
680683
// Return a new configured RoundTripper.
681684
return rt, nil
682685
}
@@ -973,7 +976,6 @@ func (rt *oauth2RoundTripper) RoundTrip(req *http.Request) (*http.Response, erro
973976
if err != nil {
974977
return nil, err
975978
}
976-
977979
rt.mtx.Lock()
978980
rt.lastSecret = newSecret
979981
rt.lastRT.Source = source

0 commit comments

Comments
 (0)