github.com/minio/madmin-go/v2@v2.2.1/transport.go (about)

     1  //
     2  // Copyright (c) 2015-2022 MinIO, Inc.
     3  //
     4  // This file is part of MinIO Object Storage stack
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU Affero General Public License as
     8  // published by the Free Software Foundation, either version 3 of the
     9  // License, or (at your option) any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU Affero General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU Affero General Public License
    17  // along with this program. If not, see <http://www.gnu.org/licenses/>.
    18  //
    19  
    20  package madmin
    21  
    22  import (
    23  	"crypto/tls"
    24  	"net"
    25  	"net/http"
    26  	"time"
    27  )
    28  
    29  // DefaultTransport - this default transport is similar to
    30  // http.DefaultTransport but with additional param  DisableCompression
    31  // is set to true to avoid decompressing content with 'gzip' encoding.
    32  var DefaultTransport = func(secure bool) http.RoundTripper {
    33  	tr := &http.Transport{
    34  		Proxy: http.ProxyFromEnvironment,
    35  		DialContext: (&net.Dialer{
    36  			Timeout:       5 * time.Second,
    37  			KeepAlive:     15 * time.Second,
    38  			FallbackDelay: 100 * time.Millisecond,
    39  		}).DialContext,
    40  		MaxIdleConns:          1024,
    41  		MaxIdleConnsPerHost:   1024,
    42  		ResponseHeaderTimeout: 60 * time.Second,
    43  		IdleConnTimeout:       60 * time.Second,
    44  		TLSHandshakeTimeout:   10 * time.Second,
    45  		ExpectContinueTimeout: 1 * time.Second,
    46  		// Set this value so that the underlying transport round-tripper
    47  		// doesn't try to auto decode the body of objects with
    48  		// content-encoding set to `gzip`.
    49  		//
    50  		// Refer:
    51  		//    https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
    52  		DisableCompression: true,
    53  	}
    54  
    55  	if secure {
    56  		tr.TLSClientConfig = &tls.Config{
    57  			// Can't use SSLv3 because of POODLE and BEAST
    58  			// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
    59  			// Can't use TLSv1.1 because of RC4 cipher usage
    60  			MinVersion: tls.VersionTLS12,
    61  		}
    62  	}
    63  	return tr
    64  }