Skip to content

Commit 000df0d

Browse files
Merge pull request rails#48437 from skipkayhil/hm-fix-rack-2-static-header
Fix duplicate Content-Type header with Rack 2
2 parents 3fc95e1 + f7c6e2c commit 000df0d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

actionpack/lib/action_dispatch/middleware/static.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def find_file(path_info, accept_encoding:)
108108
end
109109

110110
def try_files(filepath, content_type, accept_encoding:)
111-
headers = { "content-type" => content_type }
111+
headers = { Rack::CONTENT_TYPE => content_type }
112112

113113
if compressible? content_type
114114
try_precompressed_files filepath, headers, accept_encoding: accept_encoding

actionpack/test/dispatch/static_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,18 @@ def test_does_not_modify_path_info
199199
assert_equal file_name, env["PATH_INFO"]
200200
end
201201

202+
def test_only_set_one_content_type
203+
file_name = "/gzip/foo.zoo"
204+
gzip_env = { "PATH_INFO" => file_name, "HTTP_ACCEPT_ENCODING" => "gzip", "REQUEST_METHOD" => "GET" }
205+
response = @app.call(gzip_env)
206+
207+
env = { "PATH_INFO" => file_name, "REQUEST_METHOD" => "GET" }
208+
default_response = @app.call(env)
209+
210+
assert_equal 1, response[1].slice("Content-Type", "content-type").size
211+
assert_equal 1, default_response[1].slice("Content-Type", "content-type").size
212+
end
213+
202214
def test_serves_gzip_with_proper_content_type_fallback
203215
file_name = "/gzip/foo.zoo"
204216
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip")

0 commit comments

Comments
 (0)