1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge pull request #422 from mcolyer/fix-ssl-redirects

Handle Host or Protocol Changes on Redirect
This commit is contained in:
Jonas Nicklas 2011-08-11 08:25:05 -07:00
commit 4cd4b5c76a
3 changed files with 22 additions and 4 deletions

View file

@ -26,7 +26,15 @@ class Capybara::RackTest::Browser
def follow_redirects!
5.times do
follow_redirect! if last_response.redirect?
if last_response.redirect?
new_uri = URI.parse(last_response.original_headers['Location'])
if new_uri.host
@current_host = new_uri.scheme + '://' + new_uri.host
end
follow_redirect!
end
end
raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects." if last_response.redirect?
end
@ -38,17 +46,17 @@ class Capybara::RackTest::Browser
if new_uri.host
@current_host = new_uri.scheme + '://' + new_uri.host
end
if new_uri.relative?
path = request_path + path if path.start_with?('?')
unless path.start_with?('/')
folders = request_path.split('/')
path = (folders[0, folders.size - 1] << path).join('/')
end
path = current_host + path
end
reset_cache!
send(method, path, attributes, env)
follow_redirects!

View file

@ -58,5 +58,11 @@ shared_examples_for "current_host" do
@session.body.should include('Current host is http://capybara2.elabs.se')
@session.current_host.should == 'http://capybara2.elabs.se'
end
it "is affected by following a redirect" do
@session.visit('http://capybara-testapp.heroku.com/redirect_secure')
@session.body.should include('Current host is https://capybara-testapp.heroku.com')
@session.current_host.should == 'https://capybara-testapp.heroku.com'
end
end
end

View file

@ -67,6 +67,10 @@ class TestApp < Sinatra::Base
redirect back
end
get '/redirect_secure' do
redirect "https://#{request.host}/host"
end
get '/slow_response' do
sleep 2
'Finally!'