gitee.com/lh-her-team/common@v1.5.1/crypto/tls/http/http_client.go (about)

     1  package http
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"net/http"
     7  	"time"
     8  
     9  	cmtls "gitee.com/lh-her-team/common/crypto/tls"
    10  )
    11  
    12  func NewClient(config *cmtls.Config) *http.Client {
    13  	if config == nil {
    14  		panic("config must not be nil")
    15  	}
    16  	return &http.Client{
    17  		Transport: &http.Transport{
    18  			DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
    19  				dialer := &net.Dialer{}
    20  				conn, err := cmtls.DialWithDialer(dialer, network, addr, config)
    21  				if err != nil {
    22  					return nil, err
    23  				}
    24  				return conn, nil
    25  			},
    26  			Dial: (&net.Dialer{
    27  				Timeout:   30 * time.Second,
    28  				KeepAlive: 30 * time.Second,
    29  			}).Dial,
    30  			ForceAttemptHTTP2:     true,
    31  			MaxIdleConns:          100,
    32  			TLSHandshakeTimeout:   10 * time.Second,
    33  			IdleConnTimeout:       90 * time.Second,
    34  			ExpectContinueTimeout: 1 * time.Second,
    35  		},
    36  	}
    37  }