mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Pass along arguments to underlying get
method in follow_redirect!
(#33299)
* Allow get arguments for follow_redirect Now all arguments passed to `follow_redirect!` are passed to the underlying `get` method. This for example allows to set custom headers for the redirection request to the server. This is especially useful for setting headers that may, outside of the testing environment, be set automatically on every request, i.e. by a web application firewall. * Allow get arguments for follow_redirect [Remo Fritzsche + Rafael Mendonça França]
This commit is contained in:
parent
9ecbd64cd9
commit
a0061d2389
3 changed files with 24 additions and 3 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
* Pass along arguments to underlying `get` method in `follow_redirect!`
|
||||||
|
|
||||||
|
Now all arguments passed to `follow_redirect!` are passed to the underlying
|
||||||
|
`get` method. This for example allows to set custom headers for the
|
||||||
|
redirection request to the server.
|
||||||
|
|
||||||
|
follow_redirect!(params: { foo: :bar })
|
||||||
|
|
||||||
|
*Remo Fritzsche*
|
||||||
|
|
||||||
* Introduce a new error page to when the implicit render page is accessed in the browser.
|
* Introduce a new error page to when the implicit render page is accessed in the browser.
|
||||||
|
|
||||||
Now instead of showing an error page that with exception and backtraces we now show only
|
Now instead of showing an error page that with exception and backtraces we now show only
|
||||||
|
|
|
@ -50,10 +50,11 @@ module ActionDispatch
|
||||||
|
|
||||||
# Follow a single redirect response. If the last response was not a
|
# Follow a single redirect response. If the last response was not a
|
||||||
# redirect, an exception will be raised. Otherwise, the redirect is
|
# redirect, an exception will be raised. Otherwise, the redirect is
|
||||||
# performed on the location header.
|
# performed on the location header. Any arguments are passed to the
|
||||||
def follow_redirect!
|
# underlying call to `get`.
|
||||||
|
def follow_redirect!(**args)
|
||||||
raise "not a redirect! #{status} #{status_message}" unless redirect?
|
raise "not a redirect! #{status} #{status_message}" unless redirect?
|
||||||
get(response.location)
|
get(response.location, **args)
|
||||||
status
|
status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -349,6 +349,16 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_redirect_with_arguments
|
||||||
|
with_test_route_set do
|
||||||
|
get "/redirect"
|
||||||
|
follow_redirect! params: { foo: :bar }
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
assert_equal "bar", request.parameters["foo"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_xml_http_request_get
|
def test_xml_http_request_get
|
||||||
with_test_route_set do
|
with_test_route_set do
|
||||||
get "/get", xhr: true
|
get "/get", xhr: true
|
||||||
|
|
Loading…
Reference in a new issue