github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/httputil/http.go (about)

     1  // Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0.
     2  
     3  package httputil
     4  
     5  import (
     6  	"crypto/tls"
     7  	"net/http"
     8  	"time"
     9  )
    10  
    11  // NewClient returns an HTTP(s) client.
    12  func NewClient(tlsConf *tls.Config) *http.Client {
    13  	// defaultTimeout for non-context requests.
    14  	const defaultTimeout = 30 * time.Second
    15  	cli := &http.Client{Timeout: defaultTimeout}
    16  	if tlsConf != nil {
    17  		transport := http.DefaultTransport.(*http.Transport).Clone()
    18  		transport.TLSClientConfig = tlsConf
    19  		cli.Transport = transport
    20  	}
    21  	return cli
    22  }