Skip to content

Commit 629a321

Browse files
authored
Merge pull request rails#47477 from ioquatix/rack-3-static-lowercase-headers
Rack 3 static lowercase headers.
2 parents 72e73e2 + e06844f commit 629a321

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

actionpack/lib/action_dispatch/middleware/static.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def call(env)
3131
#
3232
# Precompressed versions of these files are checked first. Brotli (.br)
3333
# and gzip (.gz) files are supported. If +path+.br exists, this
34-
# endpoint returns that file with a <tt>Content-Encoding: br</tt> header.
34+
# endpoint returns that file with a <tt>content-encoding: br</tt> header.
3535
#
3636
# If no matching file is found, this endpoint responds <tt>404 Not Found</tt>.
3737
#
@@ -76,7 +76,7 @@ def serve(request, filepath, content_headers)
7676
request.path_info, ::Rack::Utils.escape_path(filepath).b
7777

7878
@file_server.call(request.env).tap do |status, headers, body|
79-
# Omit Content-Encoding/Type/etc headers for 304 Not Modified
79+
# Omit content-encoding/type/etc headers for 304 Not Modified
8080
if status != 304
8181
headers.update(content_headers)
8282
end
@@ -104,7 +104,7 @@ def find_file(path_info, accept_encoding:)
104104
end
105105

106106
def try_files(filepath, content_type, accept_encoding:)
107-
headers = { "Content-Type" => content_type }
107+
headers = { "content-type" => content_type }
108108

109109
if compressible? content_type
110110
try_precompressed_files filepath, headers, accept_encoding: accept_encoding
@@ -124,10 +124,10 @@ def try_precompressed_files(filepath, headers, accept_encoding:)
124124
if content_encoding == "identity"
125125
return precompressed_filepath, headers
126126
else
127-
headers["Vary"] = "Accept-Encoding"
127+
headers["vary"] = "accept-encoding"
128128

129129
if accept_encoding.any? { |enc, _| /\b#{content_encoding}\b/i.match?(enc) }
130-
headers["Content-Encoding"] = content_encoding
130+
headers["content-encoding"] = content_encoding
131131
return precompressed_filepath, headers
132132
end
133133
end

actionpack/test/dispatch/static_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_served_gzipped_static_file_with_non_english_filename
7979

8080
assert_gzip "/foo/さようなら.html", response
8181
assert_equal "text/html", response.headers["Content-Type"]
82-
assert_equal "Accept-Encoding", response.headers["Vary"]
82+
assert_equal "accept-encoding", response.headers["Vary"]
8383
assert_equal "gzip", response.headers["Content-Encoding"]
8484
end
8585

@@ -151,7 +151,7 @@ def test_serves_gzip_files_when_header_set
151151
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip")
152152
assert_gzip file_name, response
153153
assert_equal "application/javascript", response.headers["Content-Type"]
154-
assert_equal "Accept-Encoding", response.headers["Vary"]
154+
assert_equal "accept-encoding", response.headers["Vary"]
155155
assert_equal "gzip", response.headers["Content-Encoding"]
156156

157157
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "Gzip")
@@ -170,14 +170,14 @@ def test_serves_gzip_files_when_header_set
170170
def test_set_vary_when_origin_compressed_but_client_cant_accept
171171
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
172172
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "None")
173-
assert_equal "Accept-Encoding", response.headers["Vary"]
173+
assert_equal "accept-encoding", response.headers["Vary"]
174174
end
175175

176176
def test_serves_brotli_files_when_header_set
177177
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
178178
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "br")
179179
assert_equal "application/javascript", response.headers["Content-Type"]
180-
assert_equal "Accept-Encoding", response.headers["Vary"]
180+
assert_equal "accept-encoding", response.headers["Vary"]
181181
assert_equal "br", response.headers["Content-Encoding"]
182182

183183
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip")
@@ -188,7 +188,7 @@ def test_serves_brotli_files_before_gzip_files
188188
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
189189
response = get(file_name, "HTTP_ACCEPT_ENCODING" => "gzip, deflate, sdch, br")
190190
assert_equal "application/javascript", response.headers["Content-Type"]
191-
assert_equal "Accept-Encoding", response.headers["Vary"]
191+
assert_equal "accept-encoding", response.headers["Vary"]
192192
assert_equal "br", response.headers["Content-Encoding"]
193193
end
194194

0 commit comments

Comments
 (0)