Create only one custom transport for all S3 clients (#1722)

* Create only one custom transport for all S3 clients

Closes #1721

* Moved back to http.DefaultTransport

... because ResponseHeaderTimeout may fail `mc mirror` in slow networks
This commit is contained in:
Krishnan Parthasarathi
2016-05-21 02:07:18 -07:00
committed by Harshavardhana
parent 8b074767db
commit b48371e971
+11 -27
View File
@@ -20,7 +20,6 @@ import (
"errors"
"hash/fnv"
"io"
"net"
"net/http"
"net/url"
"os"
@@ -105,38 +104,23 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
if e != nil {
return nil, probe.NewError(e)
}
if config.Debug {
transport := http.DefaultTransport
if config.Signature == "S3v4" {
transport = httptracer.GetNewTraceTransport(newTraceV4(), http.DefaultTransport)
}
if config.Signature == "S3v2" {
transport = httptracer.GetNewTraceTransport(newTraceV2(), http.DefaultTransport)
}
// Set custom transport.
api.SetCustomTransport(transport)
}
// Cache the new minio client with hash of config as key.
clientCache[confSum] = api
}
// Set app info.
api.SetAppInfo(config.AppName, config.AppVersion)
if config.Debug {
transport := http.DefaultTransport
if config.Signature == "S3v4" {
transport = httptracer.GetNewTraceTransport(newTraceV4(), http.DefaultTransport)
}
if config.Signature == "S3v2" {
transport = httptracer.GetNewTraceTransport(newTraceV2(), http.DefaultTransport)
}
// Set custom transport.
api.SetCustomTransport(transport)
} else {
// We are using our own http.Transport value to have timeouts different from default
// where necessary.
mcDefaultTransport := http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
//Default ExpectContinueTimeout is 1sec
ExpectContinueTimeout: 3 * time.Second,
ResponseHeaderTimeout: 3 * time.Second,
}
api.SetCustomTransport(&mcDefaultTransport)
}
// Store the new api object.
s3Clnt.api = api