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

     1  package http
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"net/http"
     7  	"time"
     8  
     9  	"github.com/gorilla/websocket"
    10  
    11  	cmtls "gitee.com/lh-her-team/common/crypto/tls"
    12  )
    13  
    14  func NewDial(config *cmtls.Config) *websocket.Dialer {
    15  	if config == nil {
    16  		panic("config must not be nil")
    17  	}
    18  	return &websocket.Dialer{
    19  		NetDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
    20  			dialer := &net.Dialer{}
    21  			conn, err := cmtls.DialWithDialer(dialer, network, addr, config)
    22  			if err != nil {
    23  				return nil, err
    24  			}
    25  			return conn, nil
    26  		},
    27  		ReadBufferSize:   10,
    28  		WriteBufferSize:  10,
    29  		HandshakeTimeout: 45 * time.Second,
    30  		Proxy:            http.ProxyFromEnvironment,
    31  	}
    32  }