Skip to content

Commit 061b487

Browse files
Arthur Nogueira Nevesarthurnn
authored andcommitted
Merge pull request rails#19271 from eagletmt/304-content-type
304 response should not include Content-Type header
1 parent f12ff8d commit 061b487

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

actionpack/lib/action_dispatch/middleware/static.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def call(env)
4848
if gzip_path && gzip_encoding_accepted?(env)
4949
env['PATH_INFO'] = gzip_path
5050
status, headers, body = @file_server.call(env)
51+
if status == 304
52+
return [status, headers, body]
53+
end
5154
headers['Content-Encoding'] = 'gzip'
5255
headers['Content-Type'] = content_type(path)
5356
else

actionpack/test/dispatch/static_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def test_serves_gzip_with_propper_content_type_fallback
145145
assert_equal default_response.headers['Content-Type'], response.headers['Content-Type']
146146
end
147147

148+
def test_serves_gzip_files_with_not_modified
149+
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
150+
last_modified = File.mtime(File.join(@root, "#{file_name}.gz"))
151+
response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate)
152+
assert_equal 304, response.status
153+
assert_equal nil, response.headers['Content-Type']
154+
assert_equal nil, response.headers['Content-Encoding']
155+
assert_equal nil, response.headers['Vary']
156+
end
157+
148158
# Windows doesn't allow \ / : * ? " < > | in filenames
149159
unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
150160
def test_serves_static_file_with_colon

0 commit comments

Comments
 (0)