1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

client: add TransportWrapper to ConnectionArgs

Signed-off-by: Sebastiao Pamplona <sebastiaodsrp@gmail.com>
This commit is contained in:
Sebastiao Pamplona
2023-01-29 21:00:22 +00:00
parent 2902822e55
commit 89529781a4
2 changed files with 11 additions and 4 deletions

View File

@@ -48,6 +48,9 @@ type ConnectionArgs struct {
// Custom HTTP Client (used as base for the connection)
HTTPClient *http.Client
// TransportWrapper wraps the *http.Transport set by lxd
TransportWrapper func(*http.Transport) http.RoundTripper
// Controls whether a client verifies the server's certificate chain and host name.
InsecureSkipVerify bool
@@ -259,7 +262,7 @@ func ConnectSimpleStreams(url string, args *ConnectionArgs) (ImageServer, error)
}
// Setup the HTTP client
httpClient, err := tlsHTTPClient(args.HTTPClient, args.TLSClientCert, args.TLSClientKey, args.TLSCA, args.TLSServerCert, args.InsecureSkipVerify, args.Proxy)
httpClient, err := tlsHTTPClient(args.HTTPClient, args.TLSClientCert, args.TLSClientKey, args.TLSCA, args.TLSServerCert, args.InsecureSkipVerify, args.Proxy, args.TransportWrapper)
if err != nil {
return nil, err
}
@@ -330,7 +333,7 @@ func httpsLXD(ctx context.Context, requestURL string, args *ConnectionArgs) (Ins
}
// Setup the HTTP client
httpClient, err := tlsHTTPClient(args.HTTPClient, args.TLSClientCert, args.TLSClientKey, args.TLSCA, args.TLSServerCert, args.InsecureSkipVerify, args.Proxy)
httpClient, err := tlsHTTPClient(args.HTTPClient, args.TLSClientCert, args.TLSClientKey, args.TLSCA, args.TLSServerCert, args.InsecureSkipVerify, args.Proxy, args.TransportWrapper)
if err != nil {
return nil, err
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/lxc/lxd/shared"
)
func tlsHTTPClient(client *http.Client, tlsClientCert string, tlsClientKey string, tlsCA string, tlsServerCert string, insecureSkipVerify bool, proxy func(req *http.Request) (*url.URL, error)) (*http.Client, error) {
func tlsHTTPClient(client *http.Client, tlsClientCert string, tlsClientKey string, tlsCA string, tlsServerCert string, insecureSkipVerify bool, proxy func(req *http.Request) (*url.URL, error), transportWrapper func(t *http.Transport) http.RoundTripper) (*http.Client, error) {
// Get the TLS configuration
tlsConfig, err := shared.GetTLSConfigMem(tlsClientCert, tlsClientKey, tlsCA, tlsServerCert, insecureSkipVerify)
if err != nil {
@@ -88,7 +88,11 @@ func tlsHTTPClient(client *http.Client, tlsClientCert string, tlsClientKey strin
client = &http.Client{}
}
client.Transport = transport
if transportWrapper != nil {
client.Transport = transportWrapper(transport)
} else {
client.Transport = transport
}
// Setup redirect policy
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {