Skip to content

Commit 213c831

Browse files
committed
2 parents 05df806 + c8359a5 commit 213c831

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,16 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
218218
eventMonitor: new(eventMonitoringState),
219219
requestedAPIVersion: requestedAPIVersion,
220220
}
221-
c.initializeNativeClient()
221+
c.initializeNativeClient(defaultTransport)
222222
return c, nil
223223
}
224224

225+
// WithTransport replaces underlying HTTP client of Docker Client by accepting
226+
// a function that returns pointer to a transport object.
227+
func (c *Client) WithTransport(trFunc func () *http.Transport) {
228+
c.initializeNativeClient(trFunc)
229+
}
230+
225231
// NewVersionnedTLSClient has been DEPRECATED, please use NewVersionedTLSClient.
226232
func NewVersionnedTLSClient(endpoint string, cert, key, ca, apiVersionString string) (*Client, error) {
227233
return NewVersionedTLSClient(endpoint, cert, key, ca, apiVersionString)
@@ -339,7 +345,7 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
339345
eventMonitor: new(eventMonitoringState),
340346
requestedAPIVersion: requestedAPIVersion,
341347
}
342-
c.initializeNativeClient()
348+
c.initializeNativeClient(defaultTransport)
343349
return c, nil
344350
}
345351

client_unix.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,24 @@ package docker
99
import (
1010
"context"
1111
"net"
12+
"net/http"
1213
)
1314

1415
// initializeNativeClient initializes the native Unix domain socket client on
1516
// Unix-style operating systems
16-
func (c *Client) initializeNativeClient() {
17+
func (c *Client) initializeNativeClient(trFunc func () *http.Transport) {
1718
if c.endpointURL.Scheme != unixProtocol {
1819
return
1920
}
20-
socketPath := c.endpointURL.Path
21-
tr := defaultTransport()
21+
sockPath := c.endpointURL.Path
22+
23+
tr := trFunc()
24+
2225
tr.Dial = func(network, addr string) (net.Conn, error) {
23-
return c.Dialer.Dial(unixProtocol, socketPath)
26+
return c.Dialer.Dial(unixProtocol, sockPath)
2427
}
2528
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
26-
return c.Dialer.Dial(unixProtocol, socketPath)
29+
return c.Dialer.Dial(unixProtocol, sockPath)
2730
}
2831
c.HTTPClient.Transport = tr
2932
}

client_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"net"
1212
"time"
13+
"net/http"
1314

1415
"github.com/Microsoft/go-winio"
1516
)
@@ -25,7 +26,7 @@ func (p pipeDialer) Dial(network, address string) (net.Conn, error) {
2526
}
2627

2728
// initializeNativeClient initializes the native Named Pipe client for Windows
28-
func (c *Client) initializeNativeClient() {
29+
func (c *Client) initializeNativeClient(trFunc func () *http.Transport) {
2930
if c.endpointURL.Scheme != namedPipeProtocol {
3031
return
3132
}
@@ -34,7 +35,7 @@ func (c *Client) initializeNativeClient() {
3435
timeout := namedPipeConnectTimeout
3536
return winio.DialPipe(namedPipePath, &timeout)
3637
}
37-
tr := defaultTransport()
38+
tr := trFunc()
3839
tr.Dial = dialFunc
3940
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
4041
return dialFunc(network, addr)

0 commit comments

Comments
 (0)