Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ jobs:
filter_mode: nofilter
# Exit with 1 when it finds at least one finding.
fail_on_error: true
#golangci_lint_flags
#golangci_lint_flags
golangci_lint_version: v1.64.7
9 changes: 9 additions & 0 deletions ziface/iclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package ziface

import (
"net/http"
"net/url"
"time"
)
Expand Down Expand Up @@ -73,4 +74,12 @@ type IClient interface {
SetUrl(url *url.URL)

GetUrl() *url.URL

// Set custom headers for WebSocket connection
// 设置WebSocket连接的自定义请求头
SetWsHeader(http.Header)

// Get custom headers for WebSocket connection
// 获取WebSocket连接的自定义请求头
GetWsHeader() http.Header
}
13 changes: 12 additions & 1 deletion znet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"fmt"
"net"
"net/http"
"net/url"
"sync"
"time"
Expand All @@ -23,6 +24,8 @@ type Client struct {
// Port of the target server to connect 目标连接服务器的端口
Port int
Url *url.URL // 扩展,连接时带上其他参数
// Custom headers for WebSocket connection WebSocket连接的自定义头信息
WsHeader http.Header
// Client version tcp,websocket,客户端版本 tcp,websocket
version string
// Connection instance 连接实例
Expand Down Expand Up @@ -133,7 +136,7 @@ func (c *Client) Restart() {
}

// Create a raw socket and get net.Conn (创建原始Socket,得到net.Conn)
wsConn, _, err := c.dialer.Dial(wsAddr, nil)
wsConn, _, err := c.dialer.Dial(wsAddr, c.WsHeader)
if err != nil {
// connection failed
zlog.Ins().ErrorF("WsClient connect to server failed, err:%v", err)
Expand Down Expand Up @@ -331,3 +334,11 @@ func (c *Client) SetUrl(url *url.URL) {
func (c *Client) GetUrl() *url.URL {
return c.Url
}

func (c *Client) SetWsHeader(header http.Header) {
c.WsHeader = header
}

func (c *Client) GetWsHeader() http.Header {
return c.WsHeader
}
8 changes: 8 additions & 0 deletions znet/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package znet

import (
"net/http"
"net/url"

"github.com/aceld/zinx/ziface"
Expand Down Expand Up @@ -42,3 +43,10 @@ func WithUrl(url *url.URL) ClientOption {
c.SetUrl(url)
}
}

// Set custom headers for WebSocket connection
func WithWsHeader(header http.Header) ClientOption {
return func(c ziface.IClient) {
c.SetWsHeader(header)
}
}
Loading