Don't call controller's headers method internally
Since 5745a3c0928ee5604ce80af19348efb42189f1d6, if a controller defines a `headers` method it will be called by this line, and the return value will be mutated. This was also preventing the "Vary" header from being sent to the client. Co-authored-by: Oleksandr Bezruchenko <alex.bezruchenko@intercom.io> Co-authored-by: Iliana Hadzhiatanasova <iliana.hadzhiatanasova@intercom.io>
This commit is contained in:
parent
9868a26de4
commit
1a146bfa7a
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user