From 7082066b7c274d212e9a8aa2bc8714aef7c90c5b Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 3 May 2018 00:36:42 +1200 Subject: [PATCH] Add spec for absolute URLs. --- lib/rack/test.rb | 1 + spec/fixtures/fake_app.rb | 4 ++++ spec/rack/test_spec.rb | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/lib/rack/test.rb b/lib/rack/test.rb index 1042b247..e51c9854 100644 --- a/lib/rack/test.rb +++ b/lib/rack/test.rb @@ -197,6 +197,7 @@ def follow_redirect! # Compute the next location by appending the location header with the # last request, as per https://tools.ietf.org/html/rfc7231#section-7.1.2 + # Adding two absolute locations returns the right-hand location next_location = URI.parse(last_request.url) + URI.parse(last_response['Location']) send( diff --git a/spec/fixtures/fake_app.rb b/spec/fixtures/fake_app.rb index b0a53e9a..4b43ba55 100644 --- a/spec/fixtures/fake_app.rb +++ b/spec/fixtures/fake_app.rb @@ -28,6 +28,10 @@ class FakeApp < Sinatra::Base 'Hello World!' end + get '/absolute/redirect' do + [301, { 'location' => 'https://www.google.com' }, []] + end + post '/redirect' do if params['status'] redirect to('/redirected'), Integer(params['status']) diff --git a/spec/rack/test_spec.rb b/spec/rack/test_spec.rb index 72f470fc..01703bf2 100644 --- a/spec/rack/test_spec.rb +++ b/spec/rack/test_spec.rb @@ -366,6 +366,11 @@ def close expect(last_request.env['HTTP_REFERER']).to eql('http://example.org/redirect') end + it 'follows absolute redirects' do + get '/absolute/redirect' + expect(last_response.headers['location']).to be == 'https://www.google.com' + end + it 'follows nested redirects' do get '/nested/redirect'