Skip to content

Commit

Permalink
Removes github.com/hashicorp/go-cleanhttp dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Aug 9, 2017
1 parent 443bd55 commit bf87bce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
44 changes: 41 additions & 3 deletions client.go
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"sync/atomic"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stdcopy"
"github.com/hashicorp/go-cleanhttp"
"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"
)
Expand Down Expand Up @@ -212,7 +212,7 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
}
}
c := &Client{
HTTPClient: cleanhttp.DefaultClient(),
HTTPClient: defaultClient(),
Dialer: &net.Dialer{},
endpoint: endpoint,
endpointURL: u,
Expand Down Expand Up @@ -326,7 +326,7 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
}
tlsConfig.RootCAs = caPool
}
tr := cleanhttp.DefaultTransport()
tr := defaultTransport()
tr.TLSClientConfig = tlsConfig
if err != nil {
return nil, err
Expand Down Expand Up @@ -1040,3 +1040,41 @@ func getDockerEnv() (*dockerEnv, error) {
dockerCertPath: dockerCertPath,
}, nil
}

// defaultTransport returns a new http.Transport with similar default values to
// http.DefaultTransport, but with idle connections and keepalives disabled.
func defaultTransport() *http.Transport {
transport := defaultPooledTransport()
transport.DisableKeepAlives = true
transport.MaxIdleConnsPerHost = -1
return transport
}

// defaultPooledTransport returns a new http.Transport with similar default
// values to http.DefaultTransport. Do not use this for transient transports as
// it can leak file descriptors over time. Only use this for transports that
// will be re-used for the same host(s).
func defaultPooledTransport() *http.Transport {
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
}
return transport
}

// defaultClient returns a new http.Client with similar default values to
// http.Client, but with a non-shared Transport, idle connections disabled, and
// keepalives disabled.
func defaultClient() *http.Client {
return &http.Client{
Transport: defaultTransport(),
}
}
4 changes: 1 addition & 3 deletions client_unix.go
Expand Up @@ -10,8 +10,6 @@ import (
"context"
"net"
"net/http"

"github.com/hashicorp/go-cleanhttp"
)

// initializeNativeClient initializes the native Unix domain socket client on
Expand All @@ -21,7 +19,7 @@ func (c *Client) initializeNativeClient() {
return
}
socketPath := c.endpointURL.Path
tr := cleanhttp.DefaultTransport()
tr := defaultTransport()
tr.Dial = func(network, addr string) (net.Conn, error) {
return c.Dialer.Dial(unixProtocol, socketPath)
}
Expand Down
3 changes: 1 addition & 2 deletions client_windows.go
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/Microsoft/go-winio"
"github.com/hashicorp/go-cleanhttp"
)

const namedPipeConnectTimeout = 2 * time.Second
Expand All @@ -36,7 +35,7 @@ func (c *Client) initializeNativeClient() {
timeout := namedPipeConnectTimeout
return winio.DialPipe(namedPipePath, &timeout)
}
tr := cleanhttp.DefaultTransport()
tr := defaultTransport()
tr.Dial = dialFunc
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialFunc(network, addr)
Expand Down
4 changes: 1 addition & 3 deletions container_unix_test.go
Expand Up @@ -15,8 +15,6 @@ import (
"path/filepath"
"testing"
"time"

"github.com/hashicorp/go-cleanhttp"
)

func TestExportContainerViaUnixSocket(t *testing.T) {
Expand All @@ -29,7 +27,7 @@ func TestExportContainerViaUnixSocket(t *testing.T) {
endpoint := "unix://" + tempSocket
u, _ := parseEndpoint(endpoint, false)
client := Client{
HTTPClient: cleanhttp.DefaultClient(),
HTTPClient: defaultClient(),
Dialer: &net.Dialer{},
endpoint: endpoint,
endpointURL: u,
Expand Down

0 comments on commit bf87bce

Please sign in to comment.