mirror of
https://github.com/minio/mc.git
synced 2025-11-29 19:43:09 +03:00
Support for setting custom Transport in S3Client configuration (#3510)
This commit is contained in:
@@ -137,50 +137,55 @@ func newFactory() func(config *Config) (Client, *probe.Error) {
|
|||||||
creds = credentials.NewStaticV2(config.AccessKey, config.SecretKey, "")
|
creds = credentials.NewStaticV2(config.AccessKey, config.SecretKey, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
tr := &http.Transport{
|
var transport http.RoundTripper
|
||||||
Proxy: http.ProxyFromEnvironment,
|
|
||||||
DialContext: (&net.Dialer{
|
if config.Transport != nil {
|
||||||
Timeout: 10 * time.Second,
|
transport = config.Transport
|
||||||
KeepAlive: 15 * time.Second,
|
} else {
|
||||||
}).DialContext,
|
tr := &http.Transport{
|
||||||
MaxIdleConnsPerHost: 256,
|
Proxy: http.ProxyFromEnvironment,
|
||||||
IdleConnTimeout: 90 * time.Second,
|
DialContext: (&net.Dialer{
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
ExpectContinueTimeout: 10 * time.Second,
|
KeepAlive: 15 * time.Second,
|
||||||
// Set this value so that the underlying transport round-tripper
|
}).DialContext,
|
||||||
// doesn't try to auto decode the body of objects with
|
MaxIdleConnsPerHost: 256,
|
||||||
// content-encoding set to `gzip`.
|
IdleConnTimeout: 90 * time.Second,
|
||||||
//
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
// Refer:
|
ExpectContinueTimeout: 10 * time.Second,
|
||||||
// https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
|
// Set this value so that the underlying transport round-tripper
|
||||||
DisableCompression: true,
|
// doesn't try to auto decode the body of objects with
|
||||||
|
// content-encoding set to `gzip`.
|
||||||
|
//
|
||||||
|
// Refer:
|
||||||
|
// https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
|
||||||
|
DisableCompression: true,
|
||||||
|
}
|
||||||
|
if useTLS {
|
||||||
|
// Keep TLS config.
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
RootCAs: globalRootCAs,
|
||||||
|
// Can't use SSLv3 because of POODLE and BEAST
|
||||||
|
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
||||||
|
// Can't use TLSv1.1 because of RC4 cipher usage
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
}
|
||||||
|
if config.Insecure {
|
||||||
|
tlsConfig.InsecureSkipVerify = true
|
||||||
|
}
|
||||||
|
tr.TLSClientConfig = tlsConfig
|
||||||
|
|
||||||
|
// Because we create a custom TLSClientConfig, we have to opt-in to HTTP/2.
|
||||||
|
// See https://github.com/golang/go/issues/14275
|
||||||
|
//
|
||||||
|
// TODO: Enable http2.0 when upstream issues related to HTTP/2 are fixed.
|
||||||
|
//
|
||||||
|
// if e = http2.ConfigureTransport(tr); e != nil {
|
||||||
|
// return nil, probe.NewError(e)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
transport = tr
|
||||||
}
|
}
|
||||||
|
|
||||||
if useTLS {
|
|
||||||
// Keep TLS config.
|
|
||||||
tlsConfig := &tls.Config{
|
|
||||||
RootCAs: globalRootCAs,
|
|
||||||
// Can't use SSLv3 because of POODLE and BEAST
|
|
||||||
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
|
||||||
// Can't use TLSv1.1 because of RC4 cipher usage
|
|
||||||
MinVersion: tls.VersionTLS12,
|
|
||||||
}
|
|
||||||
if config.Insecure {
|
|
||||||
tlsConfig.InsecureSkipVerify = true
|
|
||||||
}
|
|
||||||
tr.TLSClientConfig = tlsConfig
|
|
||||||
|
|
||||||
// Because we create a custom TLSClientConfig, we have to opt-in to HTTP/2.
|
|
||||||
// See https://github.com/golang/go/issues/14275
|
|
||||||
//
|
|
||||||
// TODO: Enable http2.0 when upstream issues related to HTTP/2 are fixed.
|
|
||||||
//
|
|
||||||
// if e = http2.ConfigureTransport(tr); e != nil {
|
|
||||||
// return nil, probe.NewError(e)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
var transport http.RoundTripper = tr
|
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
if strings.EqualFold(config.Signature, "S3v4") {
|
if strings.EqualFold(config.Signature, "S3v4") {
|
||||||
transport = httptracer.GetNewTraceTransport(newTraceV4(), transport)
|
transport = httptracer.GetNewTraceTransport(newTraceV4(), transport)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -194,6 +195,7 @@ type Config struct {
|
|||||||
Debug bool
|
Debug bool
|
||||||
Insecure bool
|
Insecure bool
|
||||||
Lookup minio.BucketLookupType
|
Lookup minio.BucketLookupType
|
||||||
|
Transport *http.Transport
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectObjectOpts - opts entered for select API
|
// SelectObjectOpts - opts entered for select API
|
||||||
|
|||||||
Reference in New Issue
Block a user