mirror of https://github.com/rails/rails
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:
commit
affa3f8661
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue