From 20d4f112c5292a4646635a93f707f662140e510b Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Wed, 29 Nov 2023 10:46:28 +0100 Subject: Extract httputil package --- client/go/internal/cli/auth/auth0/auth0.go | 6 +- client/go/internal/cli/auth/zts/zts.go | 6 +- client/go/internal/cli/cmd/clone_list.go | 8 +- client/go/internal/cli/cmd/document.go | 3 +- client/go/internal/cli/cmd/feed.go | 8 +- client/go/internal/cli/cmd/root.go | 15 ++-- client/go/internal/cli/cmd/test.go | 3 +- client/go/internal/cli/cmd/testutil_test.go | 8 +- client/go/internal/httputil/httputil.go | 101 +++++++++++++++++++++++++ client/go/internal/mock/http.go | 4 +- client/go/internal/util/http.go | 95 ----------------------- client/go/internal/vespa/document/http.go | 6 +- client/go/internal/vespa/document/http_test.go | 14 ++-- client/go/internal/vespa/target.go | 8 +- client/go/internal/vespa/target_cloud.go | 6 +- client/go/internal/vespa/target_custom.go | 8 +- 16 files changed, 154 insertions(+), 145 deletions(-) create mode 100644 client/go/internal/httputil/httputil.go delete mode 100644 client/go/internal/util/http.go (limited to 'client/go/internal') diff --git a/client/go/internal/cli/auth/auth0/auth0.go b/client/go/internal/cli/auth/auth0/auth0.go index 7fae6e78b61..9466e9865b5 100644 --- a/client/go/internal/cli/auth/auth0/auth0.go +++ b/client/go/internal/cli/auth/auth0/auth0.go @@ -14,7 +14,7 @@ import ( "time" "github.com/vespa-engine/vespa/client/go/internal/cli/auth" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" ) const ( @@ -31,7 +31,7 @@ type Credentials struct { // Client is a client for the Auth0 service. type Client struct { - httpClient util.HTTPClient + httpClient httputil.Client Authenticator *auth.Authenticator // TODO: Make this private options Options provider auth0Provider @@ -80,7 +80,7 @@ func cancelOnInterrupt() context.Context { // NewClient constructs a new Auth0 client, storing configuration in the given configPath. The client will be configured for // use in the given Vespa system. -func NewClient(httpClient util.HTTPClient, options Options) (*Client, error) { +func NewClient(httpClient httputil.Client, options Options) (*Client, error) { a := Client{} a.httpClient = httpClient a.options = options diff --git a/client/go/internal/cli/auth/zts/zts.go b/client/go/internal/cli/auth/zts/zts.go index b60aa363e70..1c31ba05dd3 100644 --- a/client/go/internal/cli/auth/zts/zts.go +++ b/client/go/internal/cli/auth/zts/zts.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" ) const ( @@ -21,7 +21,7 @@ const ( // Client is a client for Athenz ZTS, an authentication token service. type Client struct { - client util.HTTPClient + client httputil.Client tokenURL *url.URL domain string now func() time.Time @@ -38,7 +38,7 @@ type Token struct { func (t *Token) isExpired(now time.Time) bool { return t.ExpiresAt.Sub(now) < expirySlack } // NewClient creates a new client for an Athenz ZTS service located at serviceURL. -func NewClient(client util.HTTPClient, domain, serviceURL string) (*Client, error) { +func NewClient(client httputil.Client, domain, serviceURL string) (*Client, error) { tokenURL, err := url.Parse(serviceURL) if err != nil { return nil, err diff --git a/client/go/internal/cli/cmd/clone_list.go b/client/go/internal/cli/cmd/clone_list.go index 40656841276..c6a99533c03 100644 --- a/client/go/internal/cli/cmd/clone_list.go +++ b/client/go/internal/cli/cmd/clone_list.go @@ -7,14 +7,14 @@ import ( "sort" "time" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" ) -func listSampleApps(client util.HTTPClient) ([]string, error) { +func listSampleApps(client httputil.Client) ([]string, error) { return listSampleAppsAt("https://api.github.com/repos/vespa-engine/sample-apps/contents/", client) } -func listSampleAppsAt(url string, client util.HTTPClient) ([]string, error) { +func listSampleAppsAt(url string, client httputil.Client) ([]string, error) { rfs, err := getRepositoryFiles(url, client) if err != nil { return nil, err @@ -36,7 +36,7 @@ func listSampleAppsAt(url string, client util.HTTPClient) ([]string, error) { return apps, nil } -func getRepositoryFiles(url string, client util.HTTPClient) ([]repositoryFile, error) { +func getRepositoryFiles(url string, client httputil.Client) ([]repositoryFile, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err diff --git a/client/go/internal/cli/cmd/document.go b/client/go/internal/cli/cmd/document.go index 6892956880b..420936cffc0 100644 --- a/client/go/internal/cli/cmd/document.go +++ b/client/go/internal/cli/cmd/document.go @@ -15,6 +15,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/util" "github.com/vespa-engine/vespa/client/go/internal/vespa" "github.com/vespa-engine/vespa/client/go/internal/vespa/document" @@ -39,7 +40,7 @@ func documentClient(cli *CLI, timeoutSecs, waitSecs int, printCurl bool) (*docum Timeout: time.Duration(timeoutSecs) * time.Second, BaseURL: docService.BaseURL, NowFunc: time.Now, - }, []util.HTTPClient{docService}) + }, []httputil.Client{docService}) if err != nil { return nil, nil, err } diff --git a/client/go/internal/cli/cmd/feed.go b/client/go/internal/cli/cmd/feed.go index 89e13a4673c..69b847547a9 100644 --- a/client/go/internal/cli/cmd/feed.go +++ b/client/go/internal/cli/cmd/feed.go @@ -12,7 +12,7 @@ import ( "time" "github.com/spf13/cobra" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/vespa/document" ) @@ -124,7 +124,7 @@ $ cat docs.jsonl | vespa feed -`, return cmd } -func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]util.HTTPClient, string, error) { +func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]httputil.Client, string, error) { if n < 1 { return nil, "", fmt.Errorf("need at least one client") } @@ -132,7 +132,7 @@ func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]uti if err != nil { return nil, "", err } - services := make([]util.HTTPClient, 0, n) + services := make([]httputil.Client, 0, n) baseURL := "" waiter := cli.waiter(time.Duration(waitSecs) * time.Second) for i := 0; i < n; i++ { @@ -144,7 +144,7 @@ func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]uti // Create a separate HTTP client for each service client := cli.httpClientFactory(timeout) // Feeding should always use HTTP/2 - util.ForceHTTP2(client, service.TLSOptions.KeyPair, service.TLSOptions.CACertificate, service.TLSOptions.TrustAll) + httputil.ForceHTTP2(client, service.TLSOptions.KeyPair, service.TLSOptions.CACertificate, service.TLSOptions.TrustAll) service.SetClient(client) services = append(services, service) } diff --git a/client/go/internal/cli/cmd/root.go b/client/go/internal/cli/cmd/root.go index 1f324658b69..2a8c2fee22f 100644 --- a/client/go/internal/cli/cmd/root.go +++ b/client/go/internal/cli/cmd/root.go @@ -20,6 +20,7 @@ import ( "github.com/vespa-engine/vespa/client/go/internal/build" "github.com/vespa-engine/vespa/client/go/internal/cli/auth/auth0" "github.com/vespa-engine/vespa/client/go/internal/cli/auth/zts" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/util" "github.com/vespa-engine/vespa/client/go/internal/version" "github.com/vespa-engine/vespa/client/go/internal/vespa" @@ -58,8 +59,8 @@ type CLI struct { config *Config version version.Version - httpClient util.HTTPClient - httpClientFactory func(timeout time.Duration) util.HTTPClient + httpClient httputil.Client + httpClientFactory func(timeout time.Duration) httputil.Client auth0Factory auth0Factory ztsFactory ztsFactory } @@ -102,9 +103,9 @@ func (c *execSubprocess) Run(name string, args ...string) ([]byte, error) { return exec.Command(name, args...).Output() } -type auth0Factory func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) +type auth0Factory func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error) -type ztsFactory func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error) +type ztsFactory func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error) // New creates the Vespa CLI, writing output to stdout and stderr, and reading environment variables from environment. func New(stdout, stderr io.Writer, environment []string) (*CLI, error) { @@ -136,7 +137,7 @@ For detailed description of flags and configuration, see 'vespa help config'. if err != nil { return nil, err } - httpClientFactory := util.CreateClient + httpClientFactory := httputil.NewClient cli := CLI{ Environment: env, Stdin: os.Stdin, @@ -152,10 +153,10 @@ For detailed description of flags and configuration, see 'vespa help config'. httpClient: httpClientFactory(time.Second * 10), httpClientFactory: httpClientFactory, - auth0Factory: func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) { + auth0Factory: func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error) { return auth0.NewClient(httpClient, options) }, - ztsFactory: func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error) { + ztsFactory: func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error) { return zts.NewClient(httpClient, domain, url) }, } diff --git a/client/go/internal/cli/cmd/test.go b/client/go/internal/cli/cmd/test.go index 376611767d9..81bf37c5653 100644 --- a/client/go/internal/cli/cmd/test.go +++ b/client/go/internal/cli/cmd/test.go @@ -21,6 +21,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/util" "github.com/vespa-engine/vespa/client/go/internal/vespa" ) @@ -277,7 +278,7 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin var response *http.Response if externalEndpoint { - util.ConfigureTLS(context.cli.httpClient, []tls.Certificate{}, nil, false) + httputil.ConfigureTLS(context.cli.httpClient, []tls.Certificate{}, nil, false) response, err = context.cli.httpClient.Do(request, 60*time.Second) } else { response, err = service.Do(request, 600*time.Second) // Vespa should provide a response within the given request timeout diff --git a/client/go/internal/cli/cmd/testutil_test.go b/client/go/internal/cli/cmd/testutil_test.go index 89f40035f6a..dbeb281a4a8 100644 --- a/client/go/internal/cli/cmd/testutil_test.go +++ b/client/go/internal/cli/cmd/testutil_test.go @@ -11,8 +11,8 @@ import ( "time" "github.com/vespa-engine/vespa/client/go/internal/cli/auth/auth0" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/mock" - "github.com/vespa-engine/vespa/client/go/internal/util" "github.com/vespa-engine/vespa/client/go/internal/vespa" ) @@ -31,13 +31,13 @@ func newTestCLI(t *testing.T, envVars ...string) (*CLI, *bytes.Buffer, *bytes.Bu t.Fatal(err) } httpClient := &mock.HTTPClient{} - cli.httpClientFactory = func(timeout time.Duration) util.HTTPClient { return httpClient } + cli.httpClientFactory = func(timeout time.Duration) httputil.Client { return httpClient } cli.httpClient = httpClient cli.exec = &mock.Exec{} - cli.auth0Factory = func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) { + cli.auth0Factory = func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error) { return &mockAuthenticator{}, nil } - cli.ztsFactory = func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error) { + cli.ztsFactory = func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error) { return &mockAuthenticator{}, nil } return cli, &stdout, &stderr diff --git a/client/go/internal/httputil/httputil.go b/client/go/internal/httputil/httputil.go new file mode 100644 index 00000000000..e1e27de5523 --- /dev/null +++ b/client/go/internal/httputil/httputil.go @@ -0,0 +1,101 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package httputil + +import ( + "context" + "crypto/tls" + "crypto/x509" + "fmt" + "net" + "net/http" + "time" + + "github.com/vespa-engine/vespa/client/go/internal/build" + "golang.org/x/net/http2" +) + +// Client represents a HTTP client usable by the Vespa CLI. +type Client interface { + Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) +} + +type defaultClient struct { + client *http.Client +} + +func (c *defaultClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) { + if c.client.Timeout != timeout { // Set wanted timeout + c.client.Timeout = timeout + } + if request.Header == nil { + request.Header = make(http.Header) + } + request.Header.Set("User-Agent", fmt.Sprintf("Vespa CLI/%s", build.Version)) + return c.client.Do(request) +} + +// ConfigureTLS configures the given client with given certificates and caCertificate. If trustAll is true, the client +// will skip verification of the certificate chain. +func ConfigureTLS(client Client, certificates []tls.Certificate, caCertificate []byte, trustAll bool) { + c, ok := client.(*defaultClient) + if !ok { + return + } + var tlsConfig *tls.Config = nil + if certificates != nil { + tlsConfig = &tls.Config{ + Certificates: certificates, + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: trustAll, + } + if caCertificate != nil { + certs := x509.NewCertPool() + certs.AppendCertsFromPEM(caCertificate) + tlsConfig.RootCAs = certs + } + } + if tr, ok := c.client.Transport.(*http.Transport); ok { + tr.TLSClientConfig = tlsConfig + } else if tr, ok := c.client.Transport.(*http2.Transport); ok { + tr.TLSClientConfig = tlsConfig + } else { + panic(fmt.Sprintf("unknown transport type: %T", c.client.Transport)) + } +} + +// ForceHTTP2 configures the given client exclusively with a HTTP/2 transport. The other options are passed to +// ConfigureTLS. If certificates is nil, the client will be configured with H2C (HTTP/2 over clear-text). +func ForceHTTP2(client Client, certificates []tls.Certificate, caCertificate []byte, trustAll bool) { + c, ok := client.(*defaultClient) + if !ok { + return + } + var dialFunc func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) + if certificates == nil { + // No certificate, so force H2C (HTTP/2 over clear-text) by using a non-TLS Dialer + dialer := net.Dialer{} + dialFunc = func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { + return dialer.DialContext(ctx, network, addr) + } + } + // Use HTTP/2 transport explicitly. Connection reuse does not work properly when using regular http.Transport, even + // though it upgrades to HTTP/2 automatically + // https://github.com/golang/go/issues/16582 + // https://github.com/golang/go/issues/22091 + c.client.Transport = &http2.Transport{ + DisableCompression: true, + AllowHTTP: true, + DialTLSContext: dialFunc, + } + ConfigureTLS(client, certificates, caCertificate, trustAll) +} + +// NewClients creates a new HTTP client the given default timeout. +func NewClient(timeout time.Duration) Client { + return &defaultClient{ + client: &http.Client{ + Timeout: timeout, + Transport: http.DefaultTransport, + }, + } +} diff --git a/client/go/internal/mock/http.go b/client/go/internal/mock/http.go index c01811c4630..06e143ab80d 100644 --- a/client/go/internal/mock/http.go +++ b/client/go/internal/mock/http.go @@ -9,7 +9,7 @@ import ( "strconv" "time" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" ) type HTTPClient struct { @@ -95,4 +95,4 @@ func (c *HTTPClient) Do(request *http.Request, timeout time.Duration) (*http.Res nil } -func (c *HTTPClient) Clone() util.HTTPClient { return c } +func (c *HTTPClient) Clone() httputil.Client { return c } diff --git a/client/go/internal/util/http.go b/client/go/internal/util/http.go deleted file mode 100644 index a7a9de5b8e4..00000000000 --- a/client/go/internal/util/http.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package util - -import ( - "context" - "crypto/tls" - "crypto/x509" - "fmt" - "net" - "net/http" - "time" - - "github.com/vespa-engine/vespa/client/go/internal/build" - "golang.org/x/net/http2" -) - -type HTTPClient interface { - Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) -} - -type defaultHTTPClient struct { - client *http.Client -} - -func (c *defaultHTTPClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) { - if c.client.Timeout != timeout { // Set wanted timeout - c.client.Timeout = timeout - } - if request.Header == nil { - request.Header = make(http.Header) - } - request.Header.Set("User-Agent", fmt.Sprintf("Vespa CLI/%s", build.Version)) - return c.client.Do(request) -} - -func ConfigureTLS(client HTTPClient, certificates []tls.Certificate, caCertificate []byte, trustAll bool) { - c, ok := client.(*defaultHTTPClient) - if !ok { - return - } - var tlsConfig *tls.Config = nil - if certificates != nil { - tlsConfig = &tls.Config{ - Certificates: certificates, - MinVersion: tls.VersionTLS12, - InsecureSkipVerify: trustAll, - } - if caCertificate != nil { - certs := x509.NewCertPool() - certs.AppendCertsFromPEM(caCertificate) - tlsConfig.RootCAs = certs - } - } - if tr, ok := c.client.Transport.(*http.Transport); ok { - tr.TLSClientConfig = tlsConfig - } else if tr, ok := c.client.Transport.(*http2.Transport); ok { - tr.TLSClientConfig = tlsConfig - } else { - panic(fmt.Sprintf("unknown transport type: %T", c.client.Transport)) - } -} - -func ForceHTTP2(client HTTPClient, certificates []tls.Certificate, caCertificate []byte, trustAll bool) { - c, ok := client.(*defaultHTTPClient) - if !ok { - return - } - var dialFunc func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) - if certificates == nil { - // No certificate, so force H2C (HTTP/2 over clear-text) by using a non-TLS Dialer - dialer := net.Dialer{} - dialFunc = func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { - return dialer.DialContext(ctx, network, addr) - } - } - // Use HTTP/2 transport explicitly. Connection reuse does not work properly when using regular http.Transport, even - // though it upgrades to HTTP/2 automatically - // https://github.com/golang/go/issues/16582 - // https://github.com/golang/go/issues/22091 - c.client.Transport = &http2.Transport{ - DisableCompression: true, - AllowHTTP: true, - DialTLSContext: dialFunc, - } - ConfigureTLS(client, certificates, caCertificate, trustAll) -} - -func CreateClient(timeout time.Duration) HTTPClient { - return &defaultHTTPClient{ - client: &http.Client{ - Timeout: timeout, - Transport: http.DefaultTransport, - }, - } -} diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go index f878938d6fc..3871ab19edd 100644 --- a/client/go/internal/vespa/document/http.go +++ b/client/go/internal/vespa/document/http.go @@ -18,7 +18,7 @@ import ( "github.com/go-json-experiment/json" "github.com/klauspost/compress/gzip" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" ) type Compression int @@ -52,7 +52,7 @@ type ClientOptions struct { } type countingHTTPClient struct { - client util.HTTPClient + client httputil.Client inflight atomic.Int64 } @@ -70,7 +70,7 @@ type pendingDocument struct { err error } -func NewClient(options ClientOptions, httpClients []util.HTTPClient) (*Client, error) { +func NewClient(options ClientOptions, httpClients []httputil.Client) (*Client, error) { if len(httpClients) < 1 { return nil, fmt.Errorf("need at least one HTTP client") } diff --git a/client/go/internal/vespa/document/http_test.go b/client/go/internal/vespa/document/http_test.go index b2c1139f95f..89e9e96064b 100644 --- a/client/go/internal/vespa/document/http_test.go +++ b/client/go/internal/vespa/document/http_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/mock" - "github.com/vespa-engine/vespa/client/go/internal/util" ) type manualClock struct { @@ -33,7 +33,7 @@ type mockHTTPClient struct { func TestLeastBusyClient(t *testing.T) { httpClient := mock.HTTPClient{} - var httpClients []util.HTTPClient + var httpClients []httputil.Client for i := 0; i < 4; i++ { httpClients = append(httpClients, &mockHTTPClient{i, &httpClient}) } @@ -83,7 +83,7 @@ func TestClientSend(t *testing.T) { client, _ := NewClient(ClientOptions{ BaseURL: "https://example.com:1337", Timeout: time.Duration(5 * time.Second), - }, []util.HTTPClient{&httpClient}) + }, []httputil.Client{&httpClient}) clock := manualClock{t: time.Now(), tick: time.Second} client.now = clock.now var stats Stats @@ -164,7 +164,7 @@ func TestClientGet(t *testing.T) { client, _ := NewClient(ClientOptions{ BaseURL: "https://example.com:1337", Timeout: time.Duration(5 * time.Second), - }, []util.HTTPClient{&httpClient}) + }, []httputil.Client{&httpClient}) clock := manualClock{t: time.Now(), tick: time.Second} client.now = clock.now doc := `{ @@ -196,7 +196,7 @@ func TestClientSendCompressed(t *testing.T) { client, _ := NewClient(ClientOptions{ BaseURL: "https://example.com:1337", Timeout: time.Duration(5 * time.Second), - }, []util.HTTPClient{httpClient}) + }, []httputil.Client{httpClient}) bigBody := fmt.Sprintf(`{"fields": {"foo": "%s"}}`, strings.Repeat("s", 512+1)) bigDoc := Document{Create: true, Id: mustParseId("id:ns:type::doc1"), Operation: OperationUpdate, Body: []byte(bigBody)} @@ -313,7 +313,7 @@ func TestClientMethodAndURL(t *testing.T) { httpClient := mock.HTTPClient{} client, _ := NewClient(ClientOptions{ BaseURL: "https://example.com/", - }, []util.HTTPClient{&httpClient}) + }, []httputil.Client{&httpClient}) for i, tt := range tests { client.options.Timeout = tt.options.Timeout client.options.Route = tt.options.Route @@ -333,7 +333,7 @@ func benchmarkClientSend(b *testing.B, compression Compression, document Documen Compression: compression, BaseURL: "https://example.com:1337", Timeout: time.Duration(5 * time.Second), - }, []util.HTTPClient{&httpClient}) + }, []httputil.Client{&httpClient}) b.ResetTimer() // ignore setup for n := 0; n < b.N; n++ { client.Send(document) diff --git a/client/go/internal/vespa/target.go b/client/go/internal/vespa/target.go index 3a76eac0292..543ce2f4a29 100644 --- a/client/go/internal/vespa/target.go +++ b/client/go/internal/vespa/target.go @@ -12,7 +12,7 @@ import ( "time" "github.com/vespa-engine/vespa/client/go/internal/curl" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/version" ) @@ -84,7 +84,7 @@ type Service struct { deployAPI bool auth Authenticator - httpClient util.HTTPClient + httpClient httputil.Client customClient bool retryInterval time.Duration } @@ -143,7 +143,7 @@ type LogOptions struct { func (s *Service) Do(request *http.Request, timeout time.Duration) (*http.Response, error) { if !s.customClient { // Do not override TLS config if a custom client has been configured - util.ConfigureTLS(s.httpClient, s.TLSOptions.KeyPair, s.TLSOptions.CACertificate, s.TLSOptions.TrustAll) + httputil.ConfigureTLS(s.httpClient, s.TLSOptions.KeyPair, s.TLSOptions.CACertificate, s.TLSOptions.TrustAll) } if s.auth != nil { if err := s.auth.Authenticate(request); err != nil { @@ -157,7 +157,7 @@ func (s *Service) Do(request *http.Request, timeout time.Duration) (*http.Respon } // SetClient sets a custom HTTP client that this service should use. -func (s *Service) SetClient(client util.HTTPClient) { +func (s *Service) SetClient(client httputil.Client) { s.httpClient = client s.customClient = true } diff --git a/client/go/internal/vespa/target_cloud.go b/client/go/internal/vespa/target_cloud.go index 708810061d2..c063b99edef 100644 --- a/client/go/internal/vespa/target_cloud.go +++ b/client/go/internal/vespa/target_cloud.go @@ -12,7 +12,7 @@ import ( "strconv" "time" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/version" ) @@ -35,7 +35,7 @@ type cloudTarget struct { apiOptions APIOptions deploymentOptions CloudDeploymentOptions logOptions LogOptions - httpClient util.HTTPClient + httpClient httputil.Client apiAuth Authenticator deploymentAuth Authenticator retryInterval time.Duration @@ -74,7 +74,7 @@ type logMessage struct { } // CloudTarget creates a Target for the Vespa Cloud or hosted Vespa platform. -func CloudTarget(httpClient util.HTTPClient, apiAuth Authenticator, deploymentAuth Authenticator, +func CloudTarget(httpClient httputil.Client, apiAuth Authenticator, deploymentAuth Authenticator, apiOptions APIOptions, deploymentOptions CloudDeploymentOptions, logOptions LogOptions, retryInterval time.Duration) (Target, error) { return &cloudTarget{ diff --git a/client/go/internal/vespa/target_custom.go b/client/go/internal/vespa/target_custom.go index 0f3817e8c13..9d62f7dc297 100644 --- a/client/go/internal/vespa/target_custom.go +++ b/client/go/internal/vespa/target_custom.go @@ -11,14 +11,14 @@ import ( "strconv" "time" - "github.com/vespa-engine/vespa/client/go/internal/util" + "github.com/vespa-engine/vespa/client/go/internal/httputil" "github.com/vespa-engine/vespa/client/go/internal/version" ) type customTarget struct { targetType string baseURL string - httpClient util.HTTPClient + httpClient httputil.Client tlsOptions TLSOptions retryInterval time.Duration } @@ -36,7 +36,7 @@ type serviceInfo struct { } // LocalTarget creates a target for a Vespa platform running locally. -func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions, retryInterval time.Duration) Target { +func LocalTarget(httpClient httputil.Client, tlsOptions TLSOptions, retryInterval time.Duration) Target { return &customTarget{ targetType: TargetLocal, baseURL: "http://127.0.0.1", @@ -47,7 +47,7 @@ func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions, retryInterva } // CustomTarget creates a Target for a Vespa platform running at baseURL. -func CustomTarget(httpClient util.HTTPClient, baseURL string, tlsOptions TLSOptions, retryInterval time.Duration) Target { +func CustomTarget(httpClient httputil.Client, baseURL string, tlsOptions TLSOptions, retryInterval time.Duration) Target { return &customTarget{ targetType: TargetCustom, baseURL: baseURL, -- cgit v1.2.3