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

Method publishHandler

internal/examples/chat/chat.go:89–104  ·  view source on GitHub ↗

publishHandler reads the request body with a limit of 8192 bytes and then publishes the received message.

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

Source from the content-addressed store, hash-verified

87// publishHandler reads the request body with a limit of 8192 bytes and then publishes
88// the received message.
89func (cs *chatServer) publishHandler(w http.ResponseWriter, r *http.Request) {
90 if r.Method != "POST" {
91 http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
92 return
93 }
94 body := http.MaxBytesReader(w, r.Body, 8192)
95 msg, err := io.ReadAll(body)
96 if err != nil {
97 http.Error(w, http.StatusText(http.StatusRequestEntityTooLarge), http.StatusRequestEntityTooLarge)
98 return
99 }
100
101 cs.publish(msg)
102
103 w.WriteHeader(http.StatusAccepted)
104}
105
106// subscribe subscribes the given WebSocket to all broadcast messages.
107// It creates a subscriber with a buffered msgs chan to give some room to slower

Callers

nothing calls this directly

Calls 2

publishMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected