MCPcopy
hub / github.com/olahol/melody / HandleRequestWithKeys

Method HandleRequestWithKeys

melody.go:145–183  ·  view source on GitHub ↗

HandleRequestWithKeys does the same as HandleRequest but populates session.Keys with keys.

(w http.ResponseWriter, r *http.Request, keys map[string]any)

Source from the content-addressed store, hash-verified

143
144// HandleRequestWithKeys does the same as HandleRequest but populates session.Keys with keys.
145func (m *Melody) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, keys map[string]any) error {
146 if m.hub.closed() {
147 return ErrClosed
148 }
149
150 conn, err := m.Upgrader.Upgrade(w, r, w.Header())
151
152 if err != nil {
153 return err
154 }
155
156 session := &Session{
157 Request: r,
158 Keys: keys,
159 conn: conn,
160 output: make(chan envelope, m.Config.MessageBufferSize),
161 outputDone: make(chan struct{}),
162 melody: m,
163 open: true,
164 }
165
166 m.hub.register(session)
167
168 m.connectHandler(session)
169
170 go session.writePump()
171
172 session.readPump()
173
174 if !m.hub.closed() {
175 m.hub.unregister(session)
176 }
177
178 session.close()
179
180 m.disconnectHandler(session)
181
182 return nil
183}
184
185// Broadcast broadcasts a text message to all sessions.
186func (m *Melody) Broadcast(msg []byte) error {

Callers 2

HandleRequestMethod · 0.95
ServeHTTPMethod · 0.80

Calls 6

writePumpMethod · 0.95
readPumpMethod · 0.95
closeMethod · 0.95
registerMethod · 0.80
unregisterMethod · 0.80
closedMethod · 0.45

Tested by 1

ServeHTTPMethod · 0.64