github.com/kubeshop/testkube@v1.17.23/pkg/http/client.go (about) 1 package http 2 3 import ( 4 "crypto/tls" 5 "net" 6 "net/http" 7 "time" 8 ) 9 10 const ( 11 NetDialTimeout = 30 * time.Second 12 TLSHandshakeTimeout = 30 * time.Second 13 ClientTimeout = 5 * time.Minute 14 ) 15 16 func NewClient(insecure ...bool) *http.Client { 17 var tlsConfig *tls.Config 18 if len(insecure) == 1 && insecure[0] { 19 tlsConfig = &tls.Config{ 20 InsecureSkipVerify: true, 21 } 22 } 23 24 var netTransport = &http.Transport{ 25 Dial: (&net.Dialer{ 26 Timeout: NetDialTimeout, 27 }).Dial, 28 TLSHandshakeTimeout: TLSHandshakeTimeout, 29 Proxy: http.ProxyFromEnvironment, 30 TLSClientConfig: tlsConfig, 31 } 32 return &http.Client{ 33 Timeout: ClientTimeout, 34 Transport: netTransport, 35 } 36 } 37 38 // NewSSEClient is HTTP client with long timeout to be able to read SSE endpoints 39 func NewSSEClient(insecure ...bool) *http.Client { 40 var netTransport *http.Transport 41 netTransport = http.DefaultTransport.(*http.Transport) 42 if len(insecure) == 1 && insecure[0] { 43 netTransport = &http.Transport{ 44 TLSClientConfig: &tls.Config{ 45 InsecureSkipVerify: true, 46 }, 47 } 48 } 49 50 return &http.Client{ 51 Timeout: time.Hour, 52 Transport: netTransport, 53 } 54 }