-
Notifications
You must be signed in to change notification settings - Fork 907
/
simplestreams.go
52 lines (41 loc) · 1.3 KB
/
simplestreams.go
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
package lxd
import (
"fmt"
"net/http"
"github.com/canonical/lxd/shared/simplestreams"
)
// ProtocolSimpleStreams implements a SimpleStreams API client.
type ProtocolSimpleStreams struct {
ssClient *simplestreams.SimpleStreams
http *http.Client
httpHost string
httpUserAgent string
httpCertificate 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, fmt.Errorf("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)
}