mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not set response "Vary" header if it has already been set
If an app sets the `"Vary"` header in an action to a value other than `"Accept"`, the `_set_vary_header` method will reset it's value to `"Accept"`. This commit checks the header to be sure that it does not already have a value before setting the header to `"Accept"`.
This commit is contained in:
parent
1074fb4ebe
commit
89c62a7bdb
2 changed files with 19 additions and 1 deletions
|
@ -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 a new issue