Add support for configuring Proxy for recws, and a go.mod mod definition file
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/mariuspass/recws"
|
"github.com/timmersuk/recws"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
module github.com/mariuspass/recws
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gorilla/websocket v1.4.0
|
||||||
|
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7
|
||||||
|
)
|
||||||
@@ -33,6 +33,9 @@ type RecConn struct {
|
|||||||
// HandshakeTimeout specifies the duration for the handshake to complete,
|
// HandshakeTimeout specifies the duration for the handshake to complete,
|
||||||
// default to 2 seconds
|
// default to 2 seconds
|
||||||
HandshakeTimeout time.Duration
|
HandshakeTimeout time.Duration
|
||||||
|
// Proxy specifies the proxy function for the dialer
|
||||||
|
// defaults to ProxyFromEnvironment
|
||||||
|
Proxy func(*http.Request) (*url.URL, error)
|
||||||
// NonVerbose suppress connecting/reconnecting messages.
|
// NonVerbose suppress connecting/reconnecting messages.
|
||||||
NonVerbose bool
|
NonVerbose bool
|
||||||
// SubscribeHandler fires after the connection successfully establish.
|
// SubscribeHandler fires after the connection successfully establish.
|
||||||
@@ -231,12 +234,22 @@ func (rc *RecConn) setDefaultHandshakeTimeout() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RecConn) setDefaultProxy() {
|
||||||
|
rc.mu.Lock()
|
||||||
|
defer rc.mu.Unlock()
|
||||||
|
|
||||||
|
if rc.Proxy == nil {
|
||||||
|
rc.Proxy = http.ProxyFromEnvironment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *RecConn) setDefaultDialer(handshakeTimeout time.Duration) {
|
func (rc *RecConn) setDefaultDialer(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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +279,7 @@ func (rc *RecConn) Dial(urlStr string, reqHeader http.Header) {
|
|||||||
rc.setDefaultRecIntvlMax()
|
rc.setDefaultRecIntvlMax()
|
||||||
rc.setDefaultRecIntvlFactor()
|
rc.setDefaultRecIntvlFactor()
|
||||||
rc.setDefaultHandshakeTimeout()
|
rc.setDefaultHandshakeTimeout()
|
||||||
|
rc.setDefaultProxy()
|
||||||
rc.setDefaultDialer(rc.getHandshakeTimeout())
|
rc.setDefaultDialer(rc.getHandshakeTimeout())
|
||||||
|
|
||||||
// Connect
|
// Connect
|
||||||
|
|||||||
Reference in New Issue
Block a user