From 89c8802baf37962d089a6653deccfac41d4c09a8 Mon Sep 17 00:00:00 2001 From: Degubi Date: Wed, 16 Oct 2024 17:18:15 +0200 Subject: [PATCH] Fix svg files not being compressed --- actix-web/CHANGES.md | 1 + actix-web/src/middleware/compress.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index cee14dc4b7e..7f6996d68f8 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -5,6 +5,7 @@ - On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use. - Update `brotli` dependency to `7`. - Minimum supported Rust version (MSRV) is now 1.75. +- Fix Svg images not being compressed by the `Compress` middleware. ## 4.9.0 diff --git a/actix-web/src/middleware/compress.rs b/actix-web/src/middleware/compress.rs index 943868d2166..fccfaffeed9 100644 --- a/actix-web/src/middleware/compress.rs +++ b/actix-web/src/middleware/compress.rs @@ -191,7 +191,12 @@ where None => true, Some(hdr) => { match hdr.to_str().ok().and_then(|hdr| hdr.parse::().ok()) { - Some(mime) if mime.type_().as_str() == "image" => false, + Some(mime) + if mime.type_().as_str() == "image" + && mime.subtype().as_str() != "svg+xml" => + { + false + } Some(mime) if mime.type_().as_str() == "video" => false, _ => true, }