MCPcopy
hub / github.com/coder/websocket / subscribeHandler

Method subscribeHandler

internal/examples/chat/chat.go:72–85  ·  view source on GitHub ↗

subscribeHandler accepts the WebSocket connection and then subscribes it to all future messages.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

70// subscribeHandler accepts the WebSocket connection and then subscribes
71// it to all future messages.
72func (cs *chatServer) subscribeHandler(w http.ResponseWriter, r *http.Request) {
73 err := cs.subscribe(w, r)
74 if errors.Is(err, context.Canceled) {
75 return
76 }
77 if websocket.CloseStatus(err) == websocket.StatusNormalClosure ||
78 websocket.CloseStatus(err) == websocket.StatusGoingAway {
79 return
80 }
81 if err != nil {
82 cs.logf("%v", err)
83 return
84 }
85}
86
87// publishHandler reads the request body with a limit of 8192 bytes and then publishes
88// the received message.

Callers

nothing calls this directly

Calls 2

subscribeMethod · 0.95
CloseStatusFunction · 0.92

Tested by

no test coverage detected