github.com/thanos-io/thanos@v0.32.5/pkg/exthttp/transport.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package exthttp 5 6 import ( 7 "net" 8 "net/http" 9 "time" 10 11 "github.com/prometheus/common/model" 12 ) 13 14 // TODO(bwplotka): HTTPConfig stores the http.Transport configuration for the cos and s3 minio client. 15 type HTTPConfig struct { 16 IdleConnTimeout model.Duration `yaml:"idle_conn_timeout"` 17 ResponseHeaderTimeout model.Duration `yaml:"response_header_timeout"` 18 InsecureSkipVerify bool `yaml:"insecure_skip_verify"` 19 20 TLSHandshakeTimeout model.Duration `yaml:"tls_handshake_timeout"` 21 ExpectContinueTimeout model.Duration `yaml:"expect_continue_timeout"` 22 MaxIdleConns int `yaml:"max_idle_conns"` 23 MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"` 24 MaxConnsPerHost int `yaml:"max_conns_per_host"` 25 26 // Transport field allows upstream callers to inject a custom round tripper. 27 Transport http.RoundTripper `yaml:"-"` 28 29 TLSConfig TLSConfig `yaml:"tls_config"` 30 DisableCompression bool `yaml:"disable_compression"` 31 } 32 33 // DefaultTransport - this default transport is based on the Minio 34 // DefaultTransport up until the following commit: 35 // https://github.com/minio/minio-go/commit/008c7aa71fc17e11bf980c209a4f8c4d687fc884 36 // The values have since diverged. 37 func DefaultTransport(config HTTPConfig) (*http.Transport, error) { 38 tlsConfig, err := NewTLSConfig(&config.TLSConfig) 39 if err != nil { 40 return nil, err 41 } 42 tlsConfig.InsecureSkipVerify = config.InsecureSkipVerify 43 44 return &http.Transport{ 45 Proxy: http.ProxyFromEnvironment, 46 DialContext: (&net.Dialer{ 47 Timeout: 30 * time.Second, 48 KeepAlive: 30 * time.Second, 49 DualStack: true, 50 }).DialContext, 51 52 MaxIdleConns: config.MaxIdleConns, 53 MaxIdleConnsPerHost: config.MaxIdleConnsPerHost, 54 IdleConnTimeout: time.Duration(config.IdleConnTimeout), 55 MaxConnsPerHost: config.MaxConnsPerHost, 56 TLSHandshakeTimeout: time.Duration(config.TLSHandshakeTimeout), 57 ExpectContinueTimeout: time.Duration(config.ExpectContinueTimeout), 58 // A custom ResponseHeaderTimeout was introduced 59 // to cover cases where the tcp connection works but 60 // the server never answers. Defaults to 2 minutes. 61 ResponseHeaderTimeout: time.Duration(config.ResponseHeaderTimeout), 62 // Set this value so that the underlying transport round-tripper 63 // doesn't try to auto decode the body of objects with 64 // content-encoding set to `gzip`. 65 // 66 // Refer: https://golang.org/src/net/http/transport.go?h=roundTrip#L1843. 67 TLSClientConfig: tlsConfig, 68 }, nil 69 }