aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/util
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-03-17 12:02:18 +0100
committerMartin Polden <mpolden@mpolden.no>2023-03-23 12:13:44 +0100
commit489e1a1b5494bb75f8238084f9779d6cc465e660 (patch)
treee8013ae9e33b3dc86e2c0c13735d86f79bb0843c /client/go/internal/util
parent7e9bc236241a5b2b0261f897116de00b94e5a27f (diff)
Expose HTTP transport
Diffstat (limited to 'client/go/internal/util')
-rw-r--r--client/go/internal/util/http.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/client/go/internal/util/http.go b/client/go/internal/util/http.go
index f47429a8d5d..b18f9a00c6a 100644
--- a/client/go/internal/util/http.go
+++ b/client/go/internal/util/http.go
@@ -12,11 +12,12 @@ import (
type HTTPClient interface {
Do(request *http.Request, timeout time.Duration) (response *http.Response, error error)
- UseCertificate(certificate []tls.Certificate)
+ Transport() *http.Transport
}
type defaultHTTPClient struct {
- client *http.Client
+ client *http.Client
+ transport *http.Transport
}
func (c *defaultHTTPClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) {
@@ -30,13 +31,24 @@ func (c *defaultHTTPClient) Do(request *http.Request, timeout time.Duration) (re
return c.client.Do(request)
}
-func (c *defaultHTTPClient) UseCertificate(certificates []tls.Certificate) {
- c.client.Transport = &http.Transport{TLSClientConfig: &tls.Config{
+func (c *defaultHTTPClient) Transport() *http.Transport { return c.transport }
+
+func SetCertificate(client HTTPClient, certificates []tls.Certificate) {
+ client.Transport().TLSClientConfig = &tls.Config{
Certificates: certificates,
MinVersion: tls.VersionTLS12,
- }}
+ }
}
func CreateClient(timeout time.Duration) HTTPClient {
- return &defaultHTTPClient{client: &http.Client{Timeout: timeout}}
+ transport := http.Transport{
+ ForceAttemptHTTP2: true,
+ }
+ return &defaultHTTPClient{
+ client: &http.Client{
+ Timeout: timeout,
+ Transport: &transport,
+ },
+ transport: &transport,
+ }
}