MCPcopy Create free account
hub / github.com/gavv/httpexpect / CloseWithBytes

Method CloseWithBytes

websocket.go:289–310  ·  view source on GitHub ↗

CloseWithBytes cleanly closes the underlying WebSocket connection by sending given slice of bytes as a close message and then waiting (with timeout) for the server to close the connection. WebSocket close code may be optionally specified. If not, then "1000 - Normal Closure" will be used. WebSocke

(b []byte, code ...int)

Source from the content-addressed store, hash-verified

287// conn := resp.Connection()
288// conn.CloseWithBytes([]byte("bye!"), websocket.CloseGoingAway)
289func (ws *Websocket) CloseWithBytes(b []byte, code ...int) *Websocket {
290 opChain := ws.chain.enter("CloseWithBytes()")
291 defer opChain.leave()
292
293 switch {
294 case ws.checkUnusable(opChain, "CloseWithBytes()"):
295 return ws
296
297 case len(code) > 1:
298 opChain.fail(AssertionFailure{
299 Type: AssertUsage,
300 Errors: []error{
301 errors.New("unexpected multiple code arguments"),
302 },
303 })
304 return ws
305 }
306
307 ws.writeMessage(opChain, websocket.CloseMessage, b, code...)
308
309 return ws
310}
311
312// CloseWithJSON cleanly closes the underlying WebSocket connection
313// by sending given object (marshaled using json.Marshal()) as a close message

Callers 2

Calls 5

checkUnusableMethod · 0.95
writeMessageMethod · 0.95
enterMethod · 0.80
leaveMethod · 0.80
failMethod · 0.80

Tested by 2