From d8dc05512374cd18bfa522d8b83bfac1f806f0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Jeaurond?= Date: Sat, 10 Feb 2024 23:22:49 -0500 Subject: [PATCH 1/2] docs: circumvent oddities with SSE and compression --- axum/src/response/sse.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index d3cc69b543..b8c88bfd24 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -24,6 +24,19 @@ //! } //! # let _: Router = app; //! ``` +//! +//! ## Compression +//! +//! By default, using the `tower-http` [compression layer](https://docs.rs/tower-http/latest/tower_http/compression/index.html) +//! with SSE will break the functionality of SSE where you will miss all or only +//! latest events. If you're using that layer, you can do the following to not +//! compress SSE: +//! +//! ```ignore +//! CompressionLayer::new() +//! .compress_when(DefaultPredicate::new() +//! .and(NotForContentType::new("text/event-stream")) +//! ``` use crate::{ body::{Bytes, HttpBody}, From 13e940304c08f7b154f7c8dd3097c7079b543414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Jeaurond?= Date: Sat, 10 Feb 2024 23:52:24 -0500 Subject: [PATCH 2/2] fix: failing doc build --- axum/src/response/sse.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index b8c88bfd24..4a83a0c169 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -32,10 +32,11 @@ //! latest events. If you're using that layer, you can do the following to not //! compress SSE: //! -//! ```ignore -//! CompressionLayer::new() -//! .compress_when(DefaultPredicate::new() -//! .and(NotForContentType::new("text/event-stream")) +//! ``` +//! # use tower_http::compression::{predicate::{NotForContentType, DefaultPredicate}, Predicate, CompressionLayer}; +//! let predicate = DefaultPredicate::new().and(NotForContentType::new("text/event-stream")); +//! +//! let layer = CompressionLayer::new().compress_when(predicate); //! ``` use crate::{