mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
custom user-agent transport wrapper (#21483)
This commit is contained in:
@@ -183,3 +183,23 @@ func (s ConnSettings) NewRemoteTargetHTTPTransport(insecure bool) func() *http.T
|
||||
return tr
|
||||
}
|
||||
}
|
||||
|
||||
// uaTransport - User-Agent transport
|
||||
type uaTransport struct {
|
||||
ua string
|
||||
rt http.RoundTripper
|
||||
}
|
||||
|
||||
func (u *uaTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
req2 := req.Clone(req.Context())
|
||||
req2.Header.Set("User-Agent", u.ua)
|
||||
return u.rt.RoundTrip(req2)
|
||||
}
|
||||
|
||||
// WithUserAgent wraps an existing transport with custom User-Agent
|
||||
func WithUserAgent(rt http.RoundTripper, getUA func() string) http.RoundTripper {
|
||||
return &uaTransport{
|
||||
ua: getUA(),
|
||||
rt: rt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user