Skip to content

Commit b9cc0a2

Browse files
authored
Merge pull request rails#50359 from flavorjones/serve-svg-with-compression_rebase
feature: Allow serving compressed SVG images (rebased)
2 parents 9517841 + 0fc5b06 commit b9cc0a2

File tree

7 files changed

+16
-1
lines changed

7 files changed

+16
-1
lines changed

actionpack/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Add `image/svg+xml` to the compressible content types of ActionDispatch::Static
2+
3+
*Georg Ledermann*
4+
15
* Add instrumentation for ActionController::Live#send_stream
26

37
Allows subscribing to `send_stream` events. The event payload contains the filename, disposition, and type.

actionpack/lib/action_dispatch/middleware/static.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class FileHandler
5050
"identity" => nil
5151
}
5252

53-
def initialize(root, index: "index", headers: {}, precompressed: %i[ br gzip ], compressible_content_types: /\A(?:text\/|application\/javascript)/)
53+
def initialize(root, index: "index", headers: {}, precompressed: %i[ br gzip ], compressible_content_types: /\A(?:text\/|application\/javascript|image\/svg\+xml)/)
5454
@root = root.chomp("/").b
5555
@index = index
5656

actionpack/test/dispatch/static_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ def test_serves_gzip_files_when_header_set
175175
assert_not_equal "gzip", response.headers["content-encoding"]
176176
end
177177

178+
def test_serves_gzip_files_when_svg
179+
file_name = "/gzip/logo-bcb6d75d927347158af5.svg"
180+
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip")
181+
assert_gzip file_name, response
182+
assert_equal "image/svg+xml", response.headers["Content-Type"]
183+
assert_equal "accept-encoding", response.headers["Vary"]
184+
assert_equal "gzip", response.headers["Content-Encoding"]
185+
end
186+
178187
def test_set_vary_when_origin_compressed_but_client_cant_accept
179188
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
180189
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "None")
Lines changed: 1 addition & 0 deletions
Loading
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Loading
Binary file not shown.

0 commit comments

Comments
 (0)