diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 9c3e292bca83c..3deb60fe19685 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -78,8 +78,8 @@ def _set_rendered_content_type(format) end def _set_vary_header - if self.headers["Vary"].blank? && request.should_apply_vary_header? - self.headers["Vary"] = "Accept" + if response.headers["Vary"].blank? && request.should_apply_vary_header? + response.headers["Vary"] = "Accept" end end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 4677c1192e21a..2fcd56e71a589 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -850,6 +850,30 @@ def app end end +class ControllerWithHeadersMethodIntegrationTest < ActionDispatch::IntegrationTest + class TestController < ActionController::Base + def index + render plain: "ok" + end + + def headers + {}.freeze + end + end + + test "doesn't call controller's headers method" do + with_routing do |routes| + routes.draw do + get "/ok" => "controller_with_headers_method_integration_test/test#index" + end + + get "/ok" + + assert_response 200 + end + end +end + class UrlOptionsIntegrationTest < ActionDispatch::IntegrationTest class FooController < ActionController::Base def index