MCPcopy Index your code
hub / github.com/coder/coder / WebsocketCloseSprintf

Function WebsocketCloseSprintf

coderd/httpapi/httpapi.go:278–290  ·  view source on GitHub ↗

WebsocketCloseSprintf formats a websocket close message and ensures it is truncated to the maximum allowed length.

(format string, vars ...any)

Source from the content-addressed store, hash-verified

276// WebsocketCloseSprintf formats a websocket close message and ensures it is
277// truncated to the maximum allowed length.
278func WebsocketCloseSprintf(format string, vars ...any) string {
279 msg := fmt.Sprintf(format, vars...)
280
281 // Cap msg length at 123 bytes. coder/websocket only allows close messages
282 // of this length.
283 if len(msg) > websocketCloseMaxLen {
284 // Trim the string to 123 bytes. If we accidentally cut in the middle of
285 // a UTF-8 character, remove it from the string.
286 return strings.ToValidUTF8(msg[:websocketCloseMaxLen], "")
287 }
288
289 return msg
290}
291
292type EventSender func(rw http.ResponseWriter, r *http.Request) (
293 sendEvent func(sse codersdk.ServerSentEvent) error,

Callers 4

followMethod · 0.92
TestWebsocketCloseMsgFunction · 0.92
workspaceAgentPTYMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestWebsocketCloseMsgFunction · 0.74