mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 07:40:48 -08:00
29 lines
570 B
Go
29 lines
570 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
type userAgentTransport struct {
|
|
inner http.RoundTripper
|
|
ua string
|
|
}
|
|
|
|
// NewUserAgent returns an http.Roundtripper that sets the user agent
|
|
//
|
|
// User-Agent: trivy/v0.64.0
|
|
func NewUserAgent(inner http.RoundTripper, ua string) http.RoundTripper {
|
|
return &userAgentTransport{
|
|
inner: inner,
|
|
ua: ua,
|
|
}
|
|
}
|
|
|
|
// RoundTrip implements http.RoundTripper
|
|
func (ut *userAgentTransport) RoundTrip(in *http.Request) (*http.Response, error) {
|
|
if ut.ua != "" {
|
|
in.Header.Set("User-Agent", ut.ua)
|
|
}
|
|
return ut.inner.RoundTrip(in)
|
|
}
|