class Amber::WebSockets::BoundedProtocol

Overview

A WebSocket protocol reader that caps how many bytes one message may accumulate while its frames and fragments arrive.

Crystal's HTTP::WebSocket reads each frame in 4 KiB blocks and joins fragments into one message. This reader counts the payload bytes of the data message being assembled (text, binary, and continuation frames) and, separately, of a control frame, as each block arrives. When a count passes max_message_bytes it sends a close frame with code 1009 (message too big) and stops reading, so an oversized message is never assembled.

Defined in:

amber/websockets/bounded_protocol.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(io : IO, max_message_bytes : Int, sync_close = true) #

[View source]

Instance Method Detail

def max_message_bytes : Int64 #

[View source]
def receive(buffer : Bytes) : HTTP::WebSocket::Protocol::PacketInfo #

[View source]