Skip to content

Commit a788831

Browse files
committed
添加websocket选项以支持自定义的Proxy
1 parent ca3f5f6 commit a788831

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

rpc/ws/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io"
2525
"net/http"
26+
"net/url"
2627
"strconv"
2728
"sync"
2829
"time"
@@ -87,6 +88,11 @@ func ConnectWithOptions(ctx context.Context, rpcEndpoint string, opt *Options) (
8788
if opt != nil && opt.HandshakeTimeout > 0 {
8889
dialer.HandshakeTimeout = opt.HandshakeTimeout
8990
}
91+
if opt != nil && opt.Proxy != "" {
92+
dialer.Proxy = func(h *http.Request) (*url.URL, error) {
93+
return url.Parse(opt.Proxy)
94+
}
95+
}
9096

9197
var httpHeader http.Header = nil
9298
if opt != nil && opt.HttpHeader != nil && len(opt.HttpHeader) > 0 {

rpc/ws/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type params struct {
7070
}
7171

7272
type Options struct {
73+
Proxy string
7374
HttpHeader http.Header
7475
HandshakeTimeout time.Duration
7576
ShortID bool // some RPC do not support int63/uint64 id, so need to enable it to rand a int31/uint32 id

0 commit comments

Comments
 (0)