Skip to main content

format_data_frame

Function format_data_frame 

Source
pub fn format_data_frame(data: &Bytes, is_binary: bool, is_json: bool) -> String
Expand description

Format an event: data SSE frame for a single stored message.

If the stream content type is binary (per is_binary_content_type), the data is base64-encoded. For JSON content types, the message is wrapped in a JSON array. Otherwise it’s sent as UTF-8 text.

For JSON streams with multiple messages from a single read, prefer format_data_frames which batches them into a single SSE event.

Multi-line data is split across multiple data: lines per the SSE spec. All line ending forms (\r\n, \r, \n) are treated as boundaries to prevent CRLF injection attacks — each segment gets its own data: prefix.