Skip to content

Commit

Permalink
Merge pull request #378 from lesismal/dev
Browse files Browse the repository at this point in the history
websocket: set KeepaliveTime to 120s by default
  • Loading branch information
lesismal committed Dec 25, 2023
2 parents d68d71f + a81e8e2 commit 01dc03b
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 01dc03b

Please sign in to comment.