File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,10 @@ use tokio::{
3232use tower:: ServiceBuilder ;
3333use tower_http:: {
3434 catch_panic:: CatchPanicLayer ,
35- compression:: CompressionLayer ,
35+ compression:: {
36+ CompressionLayer ,
37+ predicate:: { NotForContentType , Predicate , SizeAbove } ,
38+ } ,
3639 cors:: CorsLayer ,
3740 decompression:: RequestDecompressionLayer ,
3841 sensitive_headers:: SetSensitiveHeadersLayer ,
@@ -147,7 +150,15 @@ impl Application {
147150 . layer ( SetSensitiveHeadersLayer :: new ( sensitive_headers) )
148151 . layer ( CorsLayer :: permissive ( ) )
149152 . layer ( RequestDecompressionLayer :: new ( ) )
150- . layer ( CompressionLayer :: new ( ) )
153+ // Only compress responses larger than 10KB, and add the default content-type filtering
154+ . layer (
155+ CompressionLayer :: default ( ) . compress_when (
156+ SizeAbove :: new ( 10 * 1024 )
157+ . and ( NotForContentType :: GRPC )
158+ . and ( NotForContentType :: IMAGES )
159+ . and ( NotForContentType :: SSE ) ,
160+ ) ,
161+ )
151162 // Catch panics and convert them into responses.
152163 . layer ( CatchPanicLayer :: new ( ) )
153164 . layer (
You can’t perform that action at this time.
0 commit comments