Skip to content

Commit

Permalink
Get rid of nativeHTTPClient
Browse files Browse the repository at this point in the history
While reviewing fsouza#671, I noticed that we don't really need two instances
of the http client, as an instance of the docker client can only talk to
one Docker remote API.
  • Loading branch information
fsouza committed Sep 29, 2017
1 parent d6c9513 commit 20a5b5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
13 changes: 3 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ type Client struct {
requestedAPIVersion APIVersion
serverAPIVersion APIVersion
expectedAPIVersion APIVersion
nativeHTTPClient *http.Client
}

// Dialer is an interface that allows network connections to be dialed
Expand Down Expand Up @@ -344,16 +343,12 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
return c, nil
}

// SetTimeout takes a timeout and applies it to both the HTTPClient and
// nativeHTTPClient. It should not be called concurrently with any other Client
// methods.
// SetTimeout takes a timeout and applies it to the HTTPClient. It should not
// be called concurrently with any other Client methods.
func (c *Client) SetTimeout(t time.Duration) {
if c.HTTPClient != nil {
c.HTTPClient.Timeout = t
}
if c.nativeHTTPClient != nil {
c.nativeHTTPClient.Timeout = t
}
}

func (c *Client) checkAPIVersion() error {
Expand Down Expand Up @@ -445,12 +440,10 @@ func (c *Client) do(method, path string, doOptions doOptions) (*http.Response, e
return nil, err
}
}
httpClient := c.HTTPClient
protocol := c.endpointURL.Scheme
var u string
switch protocol {
case unixProtocol, namedPipeProtocol:
httpClient = c.nativeHTTPClient
u = c.getFakeNativeURL(path)
default:
u = c.getURL(path)
Expand All @@ -476,7 +469,7 @@ func (c *Client) do(method, path string, doOptions doOptions) (*http.Response, e
ctx = context.Background()
}

resp, err := ctxhttp.Do(ctx, httpClient, req)
resp, err := ctxhttp.Do(ctx, c.HTTPClient, req)
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
return nil, ErrConnectionRefused
Expand Down
3 changes: 1 addition & 2 deletions client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package docker
import (
"context"
"net"
"net/http"
)

// initializeNativeClient initializes the native Unix domain socket client on
Expand All @@ -26,5 +25,5 @@ func (c *Client) initializeNativeClient() {
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return c.Dialer.Dial(unixProtocol, socketPath)
}
c.nativeHTTPClient = &http.Client{Transport: tr}
c.HTTPClient.Transport = tr
}
7 changes: 3 additions & 4 deletions client_windows.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// +build windows

// Copyright 2016 go-dockerclient authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build windows

package docker

import (
"context"
"net"
"net/http"
"time"

"github.com/Microsoft/go-winio"
Expand Down Expand Up @@ -41,5 +40,5 @@ func (c *Client) initializeNativeClient() {
return dialFunc(network, addr)
}
c.Dialer = &pipeDialer{dialFunc}
c.nativeHTTPClient = &http.Client{Transport: tr}
c.HTTPClient.Transport = tr
}

0 comments on commit 20a5b5e

Please sign in to comment.