mirror of
https://github.com/mudler/luet.git
synced 2025-06-30 09:12:15 +00:00
24 lines
453 B
Go
24 lines
453 B
Go
package registry
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type BasicTransport struct {
|
|
Transport http.RoundTripper
|
|
URL string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
func (t *BasicTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
if strings.HasPrefix(req.URL.String(), t.URL) {
|
|
if t.Username != "" || t.Password != "" {
|
|
req.SetBasicAuth(t.Username, t.Password)
|
|
}
|
|
}
|
|
resp, err := t.Transport.RoundTrip(req)
|
|
return resp, err
|
|
}
|