Skip to content

Commit

Permalink
Remove unnessesary middleware function for BLIPSync
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks committed Nov 22, 2023
1 parent 42c868b commit 05898c6
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions rest/blip_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,20 @@ func (h *handler) handleBLIPSync() error {
// Create a BLIP WebSocket handler and have it handle the request:
server := blipContext.WebSocketServer()

middleware := func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
defer base.InfofCtx(h.ctx(), base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed", h.formatSerialNumber())
next.ServeHTTP(w, r)
})
}

go func() {
// ActiveSubprotocol only available after handshake via ServeHTTP()
if ok := server.WaitUntilStarted(h.ctx()); ok {
subprotocol := blipContext.ActiveSubprotocol()
h.logStatus(http.StatusSwitchingProtocols, fmt.Sprintf("[%s] Upgraded to WebSocket protocol %s+%s%s", blipContext.ID, blip.WebSocketSubProtocolPrefix, subprotocol, h.formattedEffectiveUserName()))
err := ctx.SetActiveCBMobileSubprotocol(subprotocol)
if err != nil {
panic(err)
base.WarnfCtx(h.ctx(), "Couldn't set active CB Mobile Subprotocol: %v", err)
}
} else {
base.InfofCtx(h.ctx(), base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed before it was accepted", h.formatSerialNumber())
}
}()

middleware(server).ServeHTTP(h.response, h.rq)
server.ServeHTTP(h.response, h.rq)
base.InfofCtx(h.ctx(), base.KeyHTTP, "%s: --> BLIP+WebSocket connection closed", h.formatSerialNumber())

return nil
}
Expand Down

0 comments on commit 05898c6

Please sign in to comment.