Allow serving compressed SVG images

This adds `image/svg+xml` to the compressible content types
of ActionDispatch::Static

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
This commit is contained in:
Georg Ledermann 2021-06-06 09:45:53 +02:00 committed by Mike Dalessio
parent 9517841bc3
commit 0fc5b06c08
No known key found for this signature in database
GPG Key ID: FCF96ED17542E12F
7 changed files with 16 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Add `image/svg+xml` to the compressible content types of ActionDispatch::Static
*Georg Ledermann*
* Add instrumentation for ActionController::Live#send_stream
Allows subscribing to `send_stream` events. The event payload contains the filename, disposition, and type.

View File

@ -50,7 +50,7 @@ module ActionDispatch
"identity" => nil
}
def initialize(root, index: "index", headers: {}, precompressed: %i[ br gzip ], compressible_content_types: /\A(?:text\/|application\/javascript)/)
def initialize(root, index: "index", headers: {}, precompressed: %i[ br gzip ], compressible_content_types: /\A(?:text\/|application\/javascript|image\/svg\+xml)/)
@root = root.chomp("/").b
@index = index

View File

@ -175,6 +175,15 @@ class StaticTest < ActiveSupport::TestCase
assert_not_equal "gzip", response.headers["content-encoding"]
end
def test_serves_gzip_files_when_svg
file_name = "/gzip/logo-bcb6d75d927347158af5.svg"
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip")
assert_gzip file_name, response
assert_equal "image/svg+xml", response.headers["Content-Type"]
assert_equal "accept-encoding", response.headers["Vary"]
assert_equal "gzip", response.headers["Content-Encoding"]
end
def test_set_vary_when_origin_compressed_but_client_cant_accept
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "None")

View File

@ -0,0 +1 @@
<svg height="155" viewBox="0 0 411 155" width="411" xmlns="http://www.w3.org/2000/svg"><g fill="#c00" fill-rule="evenodd" transform="translate(8 8)"><path d="m344.6 121.5v18.1h32.7c6.7 0 18.2-4.9 18.6-18.6v-7c0-11.7-9.6-18.6-18.6-18.6h-16.3v-8.4h32.3v-18.2h-31c-8 0-18.7 6.6-18.7 18.9v6.3c0 12.3 10.6 18.6 18.7 18.6 22.5.1-5.4 0 15.4 0v8.8m-208.3-4.3s17.5-1.5 17.5-24.1-21.2-24.7-21.2-24.7h-38.2v71.3h19.2v-17.2l16.6 17.2h28.4zm-7.4-14.6h-15.3v-16.3h15.4s4.3 1.6 4.3 8.1-4.4 8.2-4.4 8.2zm72.3-33.7h-19.5c-13.9 0-18.6 12.6-18.6 18.6v52.2h19.5v-12.5h18.3v12.5h18.9v-52.2c0-15.2-13.8-18.6-18.6-18.6zm-.3 38.1h-18.4v-17.3s0-3.9 6.1-3.9h6.7c5.4 0 5.5 3.9 5.5 3.9v17.3z"/><path d="m261.8 68.8h20.3v70.8h-20.3z"/><path d="m310.6 121.3v-52.5h-20.2v52.5 18.3h20.2 27.3v-18.3z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.1 2.6-64.9 29.1-85.9 64.1s-24 64.6-24 64.6z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.1 2.6-64.9 29.1-85.9 64.1s-24 64.6-24 64.6z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.2 2.6-65 29.1-86 64.1s-23.9 64.6-23.9 64.6zm164.6-123.1.4-6.7c-.9-.5-3.4-1.7-9.7-3.5l-.4 6.6c3.3 1.1 6.5 2.3 9.7 3.6z"/><path d="m162.1 37.7-.4 6.3c3.3.1 6.6.5 9.9 1.2l.4-6.2c-3.4-.7-6.7-1.1-9.9-1.3zm-37-31.2h1l-2-6.1c-3.1 0-6.3.2-9.6.6l1.9 5.9c2.9-.3 5.8-.4 8.7-.4zm4.8 36.8 2.3 6.9c2.9-1.4 5.8-2.6 8.7-3.5l-2.2-6.6c-3.4 1-6.3 2.1-8.8 3.2zm-45.4-26.3-4.5-6.9c-2.5 1.3-5.1 2.7-7.8 4.3l4.6 7c2.6-1.6 5.1-3.1 7.7-4.4zm20.5 45 4.8 7.2c1.7-2.5 3.7-4.8 5.9-7.1l-4.5-6.8c-2.3 2.1-4.4 4.4-6.2 6.7zm-14.5 32.2 8.1 6.4c.4-3.9 1.1-7.8 2.1-11.7l-7.2-5.7c-1.3 3.7-2.2 7.4-3 11zm-43.8-47.5-7.1-6.2c-2.6 2.5-5.1 5-7.4 7.5l7.7 6.6c2.1-2.7 4.4-5.4 6.8-7.9zm-30.2 44.7-11.5-4.2c-1.9 4.3-4 9.3-5 12l11.5 4.2c1.3-3.4 3.4-8.3 5-12zm72.5 28.2c.2 5.3.7 9.6 1.2 12.6l12 4.3c-.9-3.9-1.8-8.3-2.4-13z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1 @@
<svg height="155" viewBox="0 0 411 155" width="411" xmlns="http://www.w3.org/2000/svg"><g fill="#c00" fill-rule="evenodd" transform="translate(8 8)"><path d="m344.6 121.5v18.1h32.7c6.7 0 18.2-4.9 18.6-18.6v-7c0-11.7-9.6-18.6-18.6-18.6h-16.3v-8.4h32.3v-18.2h-31c-8 0-18.7 6.6-18.7 18.9v6.3c0 12.3 10.6 18.6 18.7 18.6 22.5.1-5.4 0 15.4 0v8.8m-208.3-4.3s17.5-1.5 17.5-24.1-21.2-24.7-21.2-24.7h-38.2v71.3h19.2v-17.2l16.6 17.2h28.4zm-7.4-14.6h-15.3v-16.3h15.4s4.3 1.6 4.3 8.1-4.4 8.2-4.4 8.2zm72.3-33.7h-19.5c-13.9 0-18.6 12.6-18.6 18.6v52.2h19.5v-12.5h18.3v12.5h18.9v-52.2c0-15.2-13.8-18.6-18.6-18.6zm-.3 38.1h-18.4v-17.3s0-3.9 6.1-3.9h6.7c5.4 0 5.5 3.9 5.5 3.9v17.3z"/><path d="m261.8 68.8h20.3v70.8h-20.3z"/><path d="m310.6 121.3v-52.5h-20.2v52.5 18.3h20.2 27.3v-18.3z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.1 2.6-64.9 29.1-85.9 64.1s-24 64.6-24 64.6z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.1 2.6-64.9 29.1-85.9 64.1s-24 64.6-24 64.6z"/><path d="m7 139.6h79s-15.1-68.9 34.9-96.8c10.9-5.3 45.6-25.1 102.4 16.9 1.8-1.5 3.5-2.7 3.5-2.7s-52-51.9-109.9-46.1c-29.2 2.6-65 29.1-86 64.1s-23.9 64.6-23.9 64.6zm164.6-123.1.4-6.7c-.9-.5-3.4-1.7-9.7-3.5l-.4 6.6c3.3 1.1 6.5 2.3 9.7 3.6z"/><path d="m162.1 37.7-.4 6.3c3.3.1 6.6.5 9.9 1.2l.4-6.2c-3.4-.7-6.7-1.1-9.9-1.3zm-37-31.2h1l-2-6.1c-3.1 0-6.3.2-9.6.6l1.9 5.9c2.9-.3 5.8-.4 8.7-.4zm4.8 36.8 2.3 6.9c2.9-1.4 5.8-2.6 8.7-3.5l-2.2-6.6c-3.4 1-6.3 2.1-8.8 3.2zm-45.4-26.3-4.5-6.9c-2.5 1.3-5.1 2.7-7.8 4.3l4.6 7c2.6-1.6 5.1-3.1 7.7-4.4zm20.5 45 4.8 7.2c1.7-2.5 3.7-4.8 5.9-7.1l-4.5-6.8c-2.3 2.1-4.4 4.4-6.2 6.7zm-14.5 32.2 8.1 6.4c.4-3.9 1.1-7.8 2.1-11.7l-7.2-5.7c-1.3 3.7-2.2 7.4-3 11zm-43.8-47.5-7.1-6.2c-2.6 2.5-5.1 5-7.4 7.5l7.7 6.6c2.1-2.7 4.4-5.4 6.8-7.9zm-30.2 44.7-11.5-4.2c-1.9 4.3-4 9.3-5 12l11.5 4.2c1.3-3.4 3.4-8.3 5-12zm72.5 28.2c.2 5.3.7 9.6 1.2 12.6l12 4.3c-.9-3.9-1.8-8.3-2.4-13z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB