feat(http): Default http transport uses the actual default values (#13437)

pull/13373/head
Leo Di Donato 2019-04-29 16:57:30 +02:00 committed by GitHub
commit 4373392d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package http
import (
"crypto/tls"
"net/http"
"net/url"
@ -55,14 +54,6 @@ func NewService(addr, token string) *Service {
}
}
// Shared transports for all clients to prevent leaking connections
var (
skipVerifyTransport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
defaultTransport = &http.Transport{}
)
func newURL(addr, path string) (*url.URL, error) {
u, err := url.Parse(addr)
if err != nil {

51
http/transport.go Normal file
View File

@ -0,0 +1,51 @@
// Shared transports for all clients to prevent leaking connections
package http
import (
"crypto/tls"
"net"
"net/http"
"time"
)
// defaultTransport is the default implementation of Transport and is
// used by traceClient. It establishes network connections as needed
// and caches them for reuse by subsequent calls. It uses HTTP proxies
// as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and
// $no_proxy) environment variables.
// This is the same as http.DefaultTransport.
//
var defaultTransport http.RoundTripper = &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,
}
// skipVerifyTransport is the default implementation of Transport and is
// used by traceClient (newClient with insecure set to true). It establishes network connections as needed
// and caches them for reuse by subsequent calls. It uses HTTP proxies
// as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and
// $no_proxy) environment variables.
// This is the same as http.DefaultTransport but with TLS skip verify.
//
var skipVerifyTransport = &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,
// This is the value that changes between this and http.DefaultTransport
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}