diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-02-06 16:58:22 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-02-19 14:15:07 +0100 |
| commit | 500da173d8a3cd2da819353f80eef6ae7ab8ecb0 (patch) | |
| tree | 0d1fa2f420b328f7f1727cc56222062603ca617d | |
| parent | 19dac4d96820993273537f6595743d703cc77c11 (diff) | |
HTTP: Make NewClient accept an underlying http client
if the argument is nil, a fresh one is automatically created
| -rw-r--r-- | internal/http/http.go | 7 | ||||
| -rw-r--r-- | internal/test/server.go | 14 |
2 files changed, 13 insertions, 8 deletions
diff --git a/internal/http/http.go b/internal/http/http.go index 4d8f3bc..ba081fd 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -147,8 +147,11 @@ type Client struct { } // Returns a HTTP client with some default settings -func NewClient() *Client { - c := &http.Client{} +func NewClient(client *http.Client) *Client { + c := client + if c == nil { + c = &http.Client{} + } // ReadLimit denotes the maximum amount of bytes that are read in HTTP responses // This is used to prevent servers from sending huge amounts of data // A limit of 16MB, although maybe much larger than needed, ensures that we do not run into problems diff --git a/internal/test/server.go b/internal/test/server.go index 71f1d00..6d6a0c2 100644 --- a/internal/test/server.go +++ b/internal/test/server.go @@ -33,12 +33,14 @@ func (srv *Server) Client() (*httpw.Client, error) { certs.AddCert(root) } } - // Override the client such that it only trusts the test server cert - client := httpw.NewClient() - client.Client.Transport = &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: certs, + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + RootCAs: certs, + }, }, } - return client, nil + // Override the client such that it only trusts the test server cert + httpC := httpw.NewClient(client) + return httpC, nil } |
