Skip to content

Commit

Permalink
Add spec for absolute URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 2, 2018
1 parent fe8b6c2 commit 7082066
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/fake_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
5 changes: 5 additions & 0 deletions spec/rack/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit 7082066

Please sign in to comment.