Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fsouza committed Jan 23, 2018
2 parents 05df806 + c8359a5 commit 213c831
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,16 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
eventMonitor: new(eventMonitoringState),
requestedAPIVersion: requestedAPIVersion,
}
c.initializeNativeClient()
c.initializeNativeClient(defaultTransport)
return c, nil
}

// WithTransport replaces underlying HTTP client of Docker Client by accepting
// a function that returns pointer to a transport object.
func (c *Client) WithTransport(trFunc func () *http.Transport) {
c.initializeNativeClient(trFunc)
}

// NewVersionnedTLSClient has been DEPRECATED, please use NewVersionedTLSClient.
func NewVersionnedTLSClient(endpoint string, cert, key, ca, apiVersionString string) (*Client, error) {
return NewVersionedTLSClient(endpoint, cert, key, ca, apiVersionString)
Expand Down Expand Up @@ -339,7 +345,7 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
eventMonitor: new(eventMonitoringState),
requestedAPIVersion: requestedAPIVersion,
}
c.initializeNativeClient()
c.initializeNativeClient(defaultTransport)
return c, nil
}

Expand Down
13 changes: 8 additions & 5 deletions client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ package docker
import (
"context"
"net"
"net/http"
)

// initializeNativeClient initializes the native Unix domain socket client on
// Unix-style operating systems
func (c *Client) initializeNativeClient() {
func (c *Client) initializeNativeClient(trFunc func () *http.Transport) {
if c.endpointURL.Scheme != unixProtocol {
return
}
socketPath := c.endpointURL.Path
tr := defaultTransport()
sockPath := c.endpointURL.Path

tr := trFunc()

tr.Dial = func(network, addr string) (net.Conn, error) {
return c.Dialer.Dial(unixProtocol, socketPath)
return c.Dialer.Dial(unixProtocol, sockPath)
}
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return c.Dialer.Dial(unixProtocol, socketPath)
return c.Dialer.Dial(unixProtocol, sockPath)
}
c.HTTPClient.Transport = tr
}
5 changes: 3 additions & 2 deletions client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"net"
"time"
"net/http"

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

// initializeNativeClient initializes the native Named Pipe client for Windows
func (c *Client) initializeNativeClient() {
func (c *Client) initializeNativeClient(trFunc func () *http.Transport) {
if c.endpointURL.Scheme != namedPipeProtocol {
return
}
Expand All @@ -34,7 +35,7 @@ func (c *Client) initializeNativeClient() {
timeout := namedPipeConnectTimeout
return winio.DialPipe(namedPipePath, &timeout)
}
tr := defaultTransport()
tr := trFunc()
tr.Dial = dialFunc
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialFunc(network, addr)
Expand Down

0 comments on commit 213c831

Please sign in to comment.