From a788831d71c93f372d545482eda01e70a639b3c3 Mon Sep 17 00:00:00 2001 From: go-enols <2575169674@qq.com> Date: Sun, 11 May 2025 21:16:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0websocket=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84?= =?UTF-8?q?Proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/ws/client.go | 6 ++++++ rpc/ws/types.go | 1 + 2 files changed, 7 insertions(+) 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