qubit_http/sse/mod.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # SSE Decoding
10//!
11//! SSE utilities built on top of [`HttpStreamResponse`](crate::HttpStreamResponse).
12//!
13//! # Author
14//!
15//! Haixing Hu
16
17mod done_marker_policy;
18mod frame_decoder;
19mod json_decoder;
20mod line_decoder;
21mod sse_chunk;
22mod sse_chunk_stream;
23mod sse_event;
24mod sse_event_stream;
25mod sse_json_mode;
26
27use crate::HttpStreamResponse;
28
29pub use done_marker_policy::DoneMarkerPolicy;
30pub use sse_chunk::SseChunk;
31pub use sse_chunk_stream::SseChunkStream;
32pub use sse_event::SseEvent;
33pub use sse_event_stream::SseEventStream;
34pub use sse_json_mode::SseJsonMode;
35
36pub(crate) use json_decoder::decode_json_chunks_from_response_with_limits;
37
38/// Parses SSE frames from a streaming HTTP response with explicit line/frame size limits.
39///
40/// # Parameters
41/// - `stream`: Streaming response whose body is SSE text.
42/// - `max_line_bytes`: Maximum allowed bytes for one SSE line.
43/// - `max_frame_bytes`: Maximum allowed bytes for one SSE frame.
44///
45/// # Returns
46/// Stream yielding [`SseEvent`] values or protocol/transport errors.
47pub(crate) fn decode_events_from_response_with_limits(
48 stream: HttpStreamResponse,
49 max_line_bytes: usize,
50 max_frame_bytes: usize,
51) -> SseEventStream {
52 let lines = line_decoder::decode_lines(stream.into_stream(), max_line_bytes);
53 frame_decoder::decode_frames(lines, max_frame_bytes)
54}