From 03c172de19fcb335ee7cb7ba4cd04096919659c1 Mon Sep 17 00:00:00 2001 From: lesismal Date: Sun, 31 Dec 2023 13:04:55 +0800 Subject: [PATCH] extension/websocket: support dial with customized dialer instance --- extension/protocol/websocket/websocket.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/extension/protocol/websocket/websocket.go b/extension/protocol/websocket/websocket.go index caa9424..4a742dc 100644 --- a/extension/protocol/websocket/websocket.go +++ b/extension/protocol/websocket/websocket.go @@ -150,8 +150,15 @@ func Listen(addr string, upgrader *websocket.Upgrader) (net.Listener, error) { } // Dial wraps websocket dial -func Dial(url string) (net.Conn, error) { - c, _, err := websocket.DefaultDialer.Dial(url, nil) +func Dial(url string, args ...interface{}) (net.Conn, error) { + dialer := websocket.DefaultDialer + if len(args) > 0 { + d, ok := args[0].(*websocket.Dialer) + if ok { + dialer = d + } + } + c, _, err := dialer.Dial(url, nil) if err != nil { return nil, err }