Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serving compressed SVG images #42407

Closed
wants to merge 8 commits into from
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Add `image/svg+xml` to the compressible content types of ActionDispatch::Static

*Georg Ledermann*

* Allow permitting numeric params.

Previously it was impossible to permit different fields on numeric parameters.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FileHandler
"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

Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/static_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_serves_gzip_files_when_header_set
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")
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.