github.com/minio/madmin-go@v1.7.5/transport.go (about)

     1  //
     2  // MinIO Object Storage (c) 2021 MinIO, Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //      http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package madmin
    18  
    19  import (
    20  	"crypto/tls"
    21  	"net"
    22  	"net/http"
    23  	"time"
    24  )
    25  
    26  // DefaultTransport - this default transport is similar to
    27  // http.DefaultTransport but with additional param  DisableCompression
    28  // is set to true to avoid decompressing content with 'gzip' encoding.
    29  var DefaultTransport = func(secure bool) http.RoundTripper {
    30  	tr := &http.Transport{
    31  		Proxy: http.ProxyFromEnvironment,
    32  		DialContext: (&net.Dialer{
    33  			Timeout:       5 * time.Second,
    34  			KeepAlive:     15 * time.Second,
    35  			FallbackDelay: 100 * time.Millisecond,
    36  		}).DialContext,
    37  		MaxIdleConns:          1024,
    38  		MaxIdleConnsPerHost:   1024,
    39  		ResponseHeaderTimeout: 60 * time.Second,
    40  		IdleConnTimeout:       60 * time.Second,
    41  		TLSHandshakeTimeout:   10 * time.Second,
    42  		ExpectContinueTimeout: 1 * time.Second,
    43  		// Set this value so that the underlying transport round-tripper
    44  		// doesn't try to auto decode the body of objects with
    45  		// content-encoding set to `gzip`.
    46  		//
    47  		// Refer:
    48  		//    https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
    49  		DisableCompression: true,
    50  	}
    51  
    52  	if secure {
    53  		tr.TLSClientConfig = &tls.Config{
    54  			// Can't use SSLv3 because of POODLE and BEAST
    55  			// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
    56  			// Can't use TLSv1.1 because of RC4 cipher usage
    57  			MinVersion: tls.VersionTLS12,
    58  		}
    59  	}
    60  	return tr
    61  }