diff --git a/rpc/ws/client.go b/rpc/ws/client.go index 64cd2a0d3..8859825a3 100644 --- a/rpc/ws/client.go +++ b/rpc/ws/client.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strconv" "sync" "time" @@ -87,6 +88,11 @@ func ConnectWithOptions(ctx context.Context, rpcEndpoint string, opt *Options) ( if opt != nil && opt.HandshakeTimeout > 0 { dialer.HandshakeTimeout = opt.HandshakeTimeout } + if opt != nil && opt.Proxy != "" { + dialer.Proxy = func(h *http.Request) (*url.URL, error) { + return url.Parse(opt.Proxy) + } + } var httpHeader http.Header = nil if opt != nil && opt.HttpHeader != nil && len(opt.HttpHeader) > 0 { diff --git a/rpc/ws/types.go b/rpc/ws/types.go index 26f942437..850963f0c 100644 --- a/rpc/ws/types.go +++ b/rpc/ws/types.go @@ -70,6 +70,7 @@ type params struct { } type Options struct { + Proxy string HttpHeader http.Header HandshakeTimeout time.Duration ShortID bool // some RPC do not support int63/uint64 id, so need to enable it to rand a int31/uint32 id