Skip to content

Commit

Permalink
websocket: set KeepaliveTime to 120s by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Dec 9, 2023
1 parent 0097556 commit a81e8e2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions nbhttp/websocket/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func NewUpgrader() *Upgrader {
u := &Upgrader{
commonFields: commonFields{
Engine: DefaultEngine,
compressionLevel: defaultCompressionLevel,
KeepaliveTime: nbhttp.DefaultKeepaliveTime,
BlockingModAsyncCloseDelay: DefaultBlockingModAsyncCloseDelay,
compressionLevel: defaultCompressionLevel,
},
BlockingModReadBufferSize: DefaultBlockingReadBufferSize,
BlockingModAsyncWrite: DefaultBlockingModAsyncWrite,
Expand Down Expand Up @@ -430,6 +431,12 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
return nil, err
}

if u.KeepaliveTime > 0 {
conn.SetReadDeadline(time.Now().Add(u.KeepaliveTime))
} else {
conn.SetReadDeadline(time.Time{})
}

if wsc.openHandler != nil {
wsc.openHandler(wsc)
}
Expand Down Expand Up @@ -560,12 +567,6 @@ func (u *Upgrader) commResponse(conn net.Conn, responseHeader http.Header, chall
return err
}

if u.KeepaliveTime <= 0 {
conn.SetReadDeadline(time.Now().Add(nbhttp.DefaultKeepaliveTime))
} else {
conn.SetReadDeadline(time.Now().Add(u.KeepaliveTime))
}

return nil
}

Expand Down

0 comments on commit a81e8e2

Please sign in to comment.