2024-04-22 12:22:15 -05:00
|
|
|
package oci
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-cleanhttp"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type userAgentTransporter struct {
|
2024-08-01 15:35:15 +01:00
|
|
|
userAgent string
|
|
|
|
|
roundTripper http.RoundTripper
|
2024-04-22 12:22:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Option = func(*http.Client)
|
|
|
|
|
|
|
|
|
|
func (u *userAgentTransporter) RoundTrip(req *http.Request) (*http.Response, error) {
|
2024-08-01 15:35:15 +01:00
|
|
|
req.Header.Set("User-Agent", u.userAgent)
|
2024-04-22 12:22:15 -05:00
|
|
|
|
2024-08-01 15:35:15 +01:00
|
|
|
return u.roundTripper.RoundTrip(req)
|
2024-04-22 12:22:15 -05:00
|
|
|
}
|
|
|
|
|
|
2024-08-01 15:35:15 +01:00
|
|
|
func HTTPTransport() http.RoundTripper {
|
2024-04-22 12:22:15 -05:00
|
|
|
return &userAgentTransporter{
|
2024-08-01 15:35:15 +01:00
|
|
|
userAgent: "Docker-Client",
|
|
|
|
|
roundTripper: cleanhttp.DefaultTransport(),
|
2024-04-22 12:22:15 -05:00
|
|
|
}
|
|
|
|
|
}
|