Merge pull request #37117 from cpruitt/vary-header-do-not-reset

Do not set response "Vary" header if it has already been set
This commit is contained in:
Eileen M. Uchitelle 2019-09-03 13:42:40 -04:00 committed by GitHub
commit affa3f8661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -78,7 +78,9 @@ module ActionController
end
def _set_vary_header
self.headers["Vary"] = "Accept" if request.should_apply_vary_header?
if self.headers["Vary"].blank? && request.should_apply_vary_header?
self.headers["Vary"] = "Accept"
end
end
# Normalize arguments by catching blocks and setting them on :update.

View File

@ -182,6 +182,15 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
end
end
def get_with_vary_set_x_requested_with
respond_to do |format|
format.json do
response.headers["Vary"] = "X-Requested-With"
render json: "JSON OK", status: 200
end
end
end
def get_with_params
render plain: "foo: #{params[:foo]}", status: 200
end
@ -557,6 +566,13 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
end
end
def test_not_setting_vary_header_when_it_has_already_been_set
with_test_route_set do
get "/get_with_vary_set_x_requested_with", headers: { "Accept" => "application/json" }, xhr: true
assert_equal "X-Requested-With", response.headers["Vary"]
end
end
def test_not_setting_vary_header_when_ignore_accept_header_is_set
original_ignore_accept_header = ActionDispatch::Request.ignore_accept_header
ActionDispatch::Request.ignore_accept_header = true