Ticket #10497: request_via_redirect.patch
| File request_via_redirect.patch, 5.5 kB (added by philodespotos, 2 years ago) |
|---|
-
a/actionpack/lib/action_controller/integration.rb
old new 121 121 status 122 122 end 123 123 124 # Performs a GET request, following any subsequent redirect. Note that125 # the redirects are followed until the response is not a redirect--this126 # means you may run into an infinite loop if your redirect loops back to127 # itself. Headers are treated in the same way as #get.128 def get_via_redirect(path, args={}, headers = {})129 get path, args, headers124 # Performs a request using the specified method, following any subsequent 125 # redirect. Note that the redirects are followed until the response is 126 # not a redirect--this means you may run into an infinite loop if your 127 # redirect loops back to itself. 128 def request_via_redirect(http_method, path, parameters = nil, headers = nil) 129 send(http_method, path, parameters, headers) 130 130 follow_redirect! while redirect? 131 131 status 132 132 end 133 133 134 # Performs a POST request, following any subsequent redirect. This is 135 # vulnerable to infinite loops, the same as #get_via_redirect. Headers are 136 # treated in the same way as #get. 137 def post_via_redirect(path, args={}, headers = {}) 138 post path, args, headers 139 follow_redirect! while redirect? 140 status 134 # Performs a GET request, following any subsequent redirect. 135 # See #request_via_redirect() for more information. 136 def get_via_redirect(path, parameters = nil, headers = nil) 137 request_via_redirect(:get, path, parameters, headers) 138 end 139 140 # Performs a POST request, following any subsequent redirect. 141 # See #request_via_redirect() for more information. 142 def post_via_redirect(path, parameters = nil, headers = nil) 143 request_via_redirect(:post, path, parameters, headers) 144 end 145 146 # Performs a PUT request, following any subsequent redirect. 147 # See #request_via_redirect() for more information. 148 def put_via_redirect(path, parameters = nil, headers = nil) 149 request_via_redirect(:put, path, parameters, headers) 150 end 151 152 # Performs a DELETE request, following any subsequent redirect. 153 # See #request_via_redirect() for more information. 154 def delete_via_redirect(path, parameters = nil, headers = nil) 155 request_via_redirect(:delete, path, parameters, headers) 141 156 end 142 157 143 158 # Returns +true+ if the last response was a redirect. -
a/actionpack/test/controller/integration_test.rb
old new 49 49 assert_equal 200, @session.follow_redirect! 50 50 end 51 51 52 def test_get_via_redirect 53 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 54 55 @session.expects(:get).with(path,args,headers) 52 def test_request_via_redirect_uses_given_method 53 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 54 @session.expects(:put).with(path, args, headers) 55 @session.stubs(:redirect?).returns(false) 56 @session.request_via_redirect(:put, path, args, headers) 57 end 56 58 59 def test_request_via_redirect_follows_redirects 60 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 57 61 @session.stubs(:redirect?).returns(true, true, false) 58 62 @session.expects(:follow_redirect!).times(2) 63 @session.request_via_redirect(:get, path, args, headers) 64 end 59 65 66 def test_request_via_redirect_returns_status 67 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 68 @session.stubs(:redirect?).returns(false) 60 69 @session.stubs(:status).returns(200) 61 assert_equal 200, @session. get_via_redirect(path, args, headers)70 assert_equal 200, @session.request_via_redirect(:get, path, args, headers) 62 71 end 63 72 64 def test_ post_via_redirect73 def test_get_via_redirect 65 74 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 75 @session.expects(:request_via_redirect).with(:get, path, args, headers) 76 @session.get_via_redirect(path, args, headers) 77 end 66 78 67 @session.expects(:post).with(path,args,headers) 79 def test_post_via_redirect 80 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 81 @session.expects(:request_via_redirect).with(:post, path, args, headers) 82 @session.post_via_redirect(path, args, headers) 83 end 68 84 69 @session.stubs(:redirect?).returns(true, true, false) 70 @session.expects(:follow_redirect!).times(2) 85 def test_put_via_redirect 86 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 87 @session.expects(:request_via_redirect).with(:put, path, args, headers) 88 @session.put_via_redirect(path, args, headers) 89 end 71 90 72 @session.stubs(:status).returns(200) 73 assert_equal 200, @session.post_via_redirect(path, args, headers) 91 def test_delete_via_redirect 92 path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 93 @session.expects(:request_via_redirect).with(:delete, path, args, headers) 94 @session.delete_via_redirect(path, args, headers) 74 95 end 75 96 76 97 def test_url_for_with_controller