Skip to content

SSE can't receive EventStream messages by browser #2034

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

You must be logged in to vote

@davidpdrsn

Based on the provided sample, I was able to investigate and resolve the issue myself.

In my code, I had enabled the CompressionLayer for all routers, which also compressed the Server-Sent Events (SSE) processing. As a result, the browser was unable to recognize the events.

use tower_http::{compression::CompressionLayer, services::ServeDir};

let app = Router::new()
        .route("/sse", get(sse_handler))
        .layer(CompressionLayer::new())

As a solution, I prevented compression when the content-type header is "text/event-stream". This allowed me to verify the functionality without any issues.

use tower_http::compression::{
    Compression, CompressionLayer
    predicate:…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@generalworksinc
Comment options

@davidpdrsn
Comment options

@generalworksinc
Comment options

@generalworksinc
Comment options

Answer selected by generalworksinc
@BenJeau
Comment options

@davidpdrsn
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants