fix(stream): add anti-buffer headers for real SSE streaming
Notify Parent Repo / dispatch (push) Canceled after 0s

- Add X-Accel-Buffering: no, Cache-Control: no-cache, Connection: keep-alive
- Prevents Traefik/proxy from buffering SSE events
- Each token is flushed immediately as generated
This commit is contained in:
Asep Haryana
2026-07-26 19:13:00 +07:00
parent 5cba76d280
commit 67861f384b
+6 -1
View File
@@ -5,6 +5,7 @@ use std::sync::Arc;
use axum::extract::State;
use axum::response::sse::{Event, KeepAlive, Sse};
use axum::http::HeaderMap;
use axum::{Json, response::{IntoResponse, Response}};
use chrono::Utc;
use tokio::sync::mpsc;
@@ -435,6 +436,10 @@ async fn handle_streaming(
});
let stream = ReceiverStream::new(rx);
let mut headers = HeaderMap::new();
headers.insert("X-Accel-Buffering", "no".parse().unwrap());
headers.insert("Cache-Control", "no-cache".parse().unwrap());
headers.insert("Connection", "keep-alive".parse().unwrap());
let sse = Sse::new(stream).keep_alive(KeepAlive::default());
Ok(sse.into_response())
Ok((headers, sse).into_response())
}