Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions crates/stringflow-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ fn apply_auth_blocking(
/// Parse SSE data lines from a buffer. Returns (events, remaining_buffer).
fn parse_sse_buffer(buffer: &str, format: WireFormat) -> (Vec<StreamEvent>, String) {
let mut events = Vec::new();
let mut remaining = String::new();

// Split on double-newline (SSE event boundaries)
let parts: Vec<&str> = buffer.split("\n\n").collect();
let last_idx = parts.len().saturating_sub(1);
let mut parts = buffer.split("\n\n").peekable();

for (i, chunk) in parts.iter().enumerate() {
while let Some(chunk) = parts.next() {
if chunk.is_empty() {
continue;
}

// Last chunk is incomplete if buffer didn't end with \n\n
if i == last_idx && !buffer.ends_with("\n\n") {
remaining = chunk.to_string();
break;
if parts.peek().is_none() && !buffer.ends_with("\n\n") {
return (events, chunk.to_owned());
}

for line in chunk.lines() {
Expand All @@ -71,7 +68,7 @@ fn parse_sse_buffer(buffer: &str, format: WireFormat) -> (Vec<StreamEvent>, Stri
}
}

(events, remaining)
(events, String::new())
}

// ============================================================================
Expand Down
Loading