Skip to content

Commit

Permalink
Create a transport based on the http.DefaultTransport.
Browse files Browse the repository at this point in the history
To respect proxy-related environment variables, we create a transport
based on http.DefaultTransport. In addition to reading proxy env vars,
it sets timeouts.

Signed-off-by: Alexander Brand <[email protected]>
  • Loading branch information
alexbrand committed Oct 23, 2019
1 parent ca1538e commit d269698
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions internal/config/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"crypto/x509"
"io/ioutil"
"log"
"net"
"net/http"
"time"
)

// TransportConfig describes a configured httpClient
Expand Down Expand Up @@ -46,15 +48,27 @@ func NewTransportConfig(trustedCAPath string) *TransportConfig {
}
}

// Trust the augmented cert pool in our client
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
// Transport based on http.DefaultTransport
t := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
}

httpClient := &http.Client{
Transport: t,
}

return &TransportConfig{
HTTPClient: httpClient,
}
Expand Down

0 comments on commit d269698

Please sign in to comment.