From 489e1a1b5494bb75f8238084f9779d6cc465e660 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Fri, 17 Mar 2023 12:02:18 +0100 Subject: Expose HTTP transport --- client/go/internal/util/http.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'client/go/internal/util') 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, + } } -- cgit v1.2.3