Add dialer property in config (#1179)
Co-authored-by: eeWynell <eewynell@gmail.com>
This commit is contained in:
parent
c0803d021f
commit
262e8ba52b
3 changed files with 7 additions and 1 deletions
|
@ -17,6 +17,8 @@ import (
|
|||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
|
||||
|
@ -41,6 +43,7 @@ func New(token string) (s *Session, err error) {
|
|||
ShardCount: 1,
|
||||
MaxRestRetries: 3,
|
||||
Client: &http.Client{Timeout: (20 * time.Second)},
|
||||
Dialer: websocket.DefaultDialer,
|
||||
UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
|
||||
sequence: new(int64),
|
||||
LastHeartbeatAck: time.Now().UTC(),
|
||||
|
|
|
@ -95,6 +95,9 @@ type Session struct {
|
|||
// The http client used for REST requests
|
||||
Client *http.Client
|
||||
|
||||
// The dialer used for WebSocket connection
|
||||
Dialer *websocket.Dialer
|
||||
|
||||
// The user agent used for REST APIs
|
||||
UserAgent string
|
||||
|
||||
|
|
2
wsapi.go
2
wsapi.go
|
@ -77,7 +77,7 @@ func (s *Session) Open() error {
|
|||
s.log(LogInformational, "connecting to gateway %s", s.gateway)
|
||||
header := http.Header{}
|
||||
header.Add("accept-encoding", "zlib")
|
||||
s.wsConn, _, err = websocket.DefaultDialer.Dial(s.gateway, header)
|
||||
s.wsConn, _, err = s.Dialer.Dial(s.gateway, header)
|
||||
if err != nil {
|
||||
s.log(LogError, "error connecting to gateway %s, %s", s.gateway, err)
|
||||
s.gateway = "" // clear cached gateway
|
||||
|
|
Loading…
Reference in a new issue