This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2021-01-16 20:41:39 +00:00
|
|
|
package ak
|
2020-11-29 18:01:15 +00:00
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
func SetUserAgent(inner http.RoundTripper, userAgent string) http.RoundTripper {
|
|
|
|
return &addUGA{
|
|
|
|
inner: inner,
|
|
|
|
Agent: userAgent,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type addUGA struct {
|
|
|
|
inner http.RoundTripper
|
|
|
|
Agent string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ug *addUGA) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
|
|
r.Header.Set("User-Agent", ug.Agent)
|
|
|
|
return ug.inner.RoundTrip(r)
|
|
|
|
}
|