Skip to content

SSE response taking a long time - IE, what am I doing wrong? #2694

Closed Answered by kmanc
kmanc asked this question in Q&A
Discussion options

You must be logged in to vote

For any unfortunate soul in the same position as me, the problem wasn't really the code on either the Rust or React side...it was Nginx.

You can fix by changing the Sse handler into the following, see this link for details

async fn sse_handler() -> impl IntoResponse {
    // A `Stream` that repeats an event every second
    let stream = stream::repeat_with(|| Event::default().data("hi!"))
        .map(Ok)
        .throttle(Duration::from_secs(1));

    let mut resp = Sse::new(stream).keep_alive(KeepAlive::default()).into_response();
    resp.headers_mut().insert("X-Accel-Buffering", "no".parse().unwrap());
    resp
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kmanc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant