1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package incus
import (
"errors"
"net/http"
"github.com/lxc/incus/v6/shared/simplestreams"
)
// ProtocolSimpleStreams implements a SimpleStreams API client.
type ProtocolSimpleStreams struct {
ssClient *simplestreams.SimpleStreams
http *http.Client
httpHost string
httpUserAgent string
httpCertificate string
tempPath string
}
// Disconnect is a no-op for simplestreams.
func (r *ProtocolSimpleStreams) Disconnect() {
}
// GetConnectionInfo returns the basic connection information used to interact with the server.
func (r *ProtocolSimpleStreams) GetConnectionInfo() (*ConnectionInfo, error) {
info := ConnectionInfo{}
info.Addresses = []string{r.httpHost}
info.Certificate = r.httpCertificate
info.Protocol = "simplestreams"
info.URL = r.httpHost
return &info, nil
}
// GetHTTPClient returns the http client used for the connection. This can be used to set custom http options.
func (r *ProtocolSimpleStreams) GetHTTPClient() (*http.Client, error) {
if r.http == nil {
return nil, errors.New("HTTP client isn't set, bad connection")
}
return r.http, nil
}
// DoHTTP performs a Request.
func (r *ProtocolSimpleStreams) DoHTTP(req *http.Request) (*http.Response, error) {
// Set the user agent
if r.httpUserAgent != "" {
req.Header.Set("User-Agent", r.httpUserAgent)
}
return r.http.Do(req)
}
|