diff options
author | Kohei Suzuki <eagletmt@gmail.com> | 2015-03-10 16:51:51 +0900 |
---|---|---|
committer | Kohei Suzuki <eagletmt@gmail.com> | 2015-03-10 23:39:08 +0900 |
commit | d4103fc232044625c6ba4692b4c9bd8779e97ba5 (patch) | |
tree | bb6475ff3928e412b69347b31bf9d10e772651e5 | |
parent | 221e847a3bc4b6dc2559b4354417862b2e6c684a (diff) | |
download | rails-d4103fc232044625c6ba4692b4c9bd8779e97ba5.tar.gz rails-d4103fc232044625c6ba4692b4c9bd8779e97ba5.tar.bz2 rails-d4103fc232044625c6ba4692b4c9bd8779e97ba5.zip |
304 response should not include Content-Type header
Rack::Lint raises an error saying "Content-Type header found in 304
response, not allowed".
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/static.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/static_test.rb | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 2e1bd45c3d..f5c2acbfb9 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -48,7 +48,9 @@ module ActionDispatch env['PATH_INFO'] = gzip_path status, headers, body = @file_server.call(env) headers['Content-Encoding'] = 'gzip' - headers['Content-Type'] = content_type(path) + if status != 304 + headers['Content-Type'] = content_type(path) + end else status, headers, body = @file_server.call(env) end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index ebc9d71403..9164cbd3aa 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -143,6 +143,15 @@ module StaticTests assert_equal default_response.headers['Content-Type'], response.headers['Content-Type'] end + def test_serves_gzip_files_with_not_modified + file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" + last_modified = File.mtime(File.join(@root, "#{file_name}.gz")) + response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate) + assert_equal 304, response.status + assert_equal nil, response.headers['Content-Type'] + assert_equal 'gzip', response.headers['Content-Encoding'] + end + # Windows doesn't allow \ / : * ? " < > | in filenames unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ def test_serves_static_file_with_colon |