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

Function parseClosePayload

close.go:254–275  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

252}
253
254func parseClosePayload(p []byte) (CloseError, error) {
255 if len(p) == 0 {
256 return CloseError{
257 Code: StatusNoStatusRcvd,
258 }, nil
259 }
260
261 if len(p) < 2 {
262 return CloseError{}, fmt.Errorf("close payload %q too small, cannot even contain the 2 byte status code", p)
263 }
264
265 ce := CloseError{
266 Code: StatusCode(binary.BigEndian.Uint16(p)),
267 Reason: string(p[2:]),
268 }
269
270 if !validWireCloseCode(ce.Code) {
271 return CloseError{}, fmt.Errorf("invalid status code %v", ce.Code)
272 }
273
274 return ce, nil
275}
276
277// See http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
278// and https://tools.ietf.org/html/rfc6455#section-7.4.1

Callers 2

Test_parseClosePayloadFunction · 0.85
handleControlMethod · 0.85

Calls 2

validWireCloseCodeFunction · 0.85
StatusCodeTypeAlias · 0.70

Tested by 1

Test_parseClosePayloadFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…