ability to disable certificate check
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
package recws
|
package recws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -36,6 +37,7 @@ type RecConn struct {
|
|||||||
// Proxy specifies the proxy function for the dialer
|
// Proxy specifies the proxy function for the dialer
|
||||||
// defaults to ProxyFromEnvironment
|
// defaults to ProxyFromEnvironment
|
||||||
Proxy func(*http.Request) (*url.URL, error)
|
Proxy func(*http.Request) (*url.URL, error)
|
||||||
|
TLSClientConfig *tls.Config
|
||||||
// SubscribeHandler fires after the connection successfully establish.
|
// SubscribeHandler fires after the connection successfully establish.
|
||||||
SubscribeHandler func() error
|
SubscribeHandler func() error
|
||||||
// KeepAliveTimeout is an interval for sending ping/pong messages
|
// KeepAliveTimeout is an interval for sending ping/pong messages
|
||||||
@@ -243,13 +245,14 @@ func (rc *RecConn) setDefaultProxy() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RecConn) setDefaultDialer(handshakeTimeout time.Duration) {
|
func (rc *RecConn) setDefaultDialer(tlsClientConfig *tls.Config, handshakeTimeout time.Duration) {
|
||||||
rc.mu.Lock()
|
rc.mu.Lock()
|
||||||
defer rc.mu.Unlock()
|
defer rc.mu.Unlock()
|
||||||
|
|
||||||
rc.dialer = &websocket.Dialer{
|
rc.dialer = &websocket.Dialer{
|
||||||
HandshakeTimeout: handshakeTimeout,
|
HandshakeTimeout: handshakeTimeout,
|
||||||
Proxy: rc.Proxy,
|
Proxy: rc.Proxy,
|
||||||
|
TLSClientConfig: tlsClientConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +263,20 @@ func (rc *RecConn) getHandshakeTimeout() time.Duration {
|
|||||||
return rc.HandshakeTimeout
|
return rc.HandshakeTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RecConn) getTLSClientConfig() *tls.Config {
|
||||||
|
rc.mu.RLock()
|
||||||
|
defer rc.mu.RUnlock()
|
||||||
|
|
||||||
|
return rc.TLSClientConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RecConn) SetTLSClientConfig(tlsClientConfig *tls.Config) {
|
||||||
|
rc.mu.Lock()
|
||||||
|
defer rc.mu.Unlock()
|
||||||
|
|
||||||
|
rc.TLSClientConfig = tlsClientConfig
|
||||||
|
}
|
||||||
|
|
||||||
// Dial creates a new client connection.
|
// Dial creates a new client connection.
|
||||||
// The URL url specifies the host and request URI. Use requestHeader to specify
|
// The URL url specifies the host and request URI. Use requestHeader to specify
|
||||||
// the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies
|
// the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies
|
||||||
@@ -280,7 +297,7 @@ func (rc *RecConn) Dial(urlStr string, reqHeader http.Header) {
|
|||||||
rc.setDefaultRecIntvlFactor()
|
rc.setDefaultRecIntvlFactor()
|
||||||
rc.setDefaultHandshakeTimeout()
|
rc.setDefaultHandshakeTimeout()
|
||||||
rc.setDefaultProxy()
|
rc.setDefaultProxy()
|
||||||
rc.setDefaultDialer(rc.getHandshakeTimeout())
|
rc.setDefaultDialer(rc.getTLSClientConfig(), rc.getHandshakeTimeout())
|
||||||
|
|
||||||
// Connect
|
// Connect
|
||||||
go rc.connect()
|
go rc.connect()
|
||||||
|
|||||||
Reference in New Issue
Block a user