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
15 changes: 13 additions & 2 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ use tokio::{
use tower::ServiceBuilder;
use tower_http::{
catch_panic::CatchPanicLayer,
compression::CompressionLayer,
compression::{
CompressionLayer,
predicate::{NotForContentType, Predicate, SizeAbove},
},
cors::CorsLayer,
decompression::RequestDecompressionLayer,
sensitive_headers::SetSensitiveHeadersLayer,
Expand Down Expand Up @@ -147,7 +150,15 @@ impl Application {
.layer(SetSensitiveHeadersLayer::new(sensitive_headers))
.layer(CorsLayer::permissive())
.layer(RequestDecompressionLayer::new())
.layer(CompressionLayer::new())
// Only compress responses larger than 10KB, and add the default content-type filtering
.layer(
CompressionLayer::default().compress_when(
SizeAbove::new(10 * 1024)
.and(NotForContentType::GRPC)
.and(NotForContentType::IMAGES)
.and(NotForContentType::SSE),
),
)
// Catch panics and convert them into responses.
.layer(CatchPanicLayer::new())
.layer(
Expand Down