1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Allow URI objects as redirect targets

This commit is contained in:
Nicolas Sanguinetti 2013-01-07 00:30:20 -02:00
parent 3d0cef2ea7
commit 84dcea3309
2 changed files with 12 additions and 1 deletions

View file

@ -173,7 +173,7 @@ module Sinatra
# According to RFC 2616 section 14.30, "the field value consists of a
# single absolute URI"
response['Location'] = uri(uri, settings.absolute_redirects?, settings.prefixed_redirects?)
response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?)
halt(*args)
end

View file

@ -240,6 +240,17 @@ class HelpersTest < Test::Unit::TestCase
assert_equal '', body
assert_equal 'mailto:jsmith@example.com', response['Location']
end
it 'accepts a URI object instead of a String' do
mock_app do
get('/') { redirect URI.parse('http://sinatrarb.com') }
end
get '/'
assert_equal 302, status
assert_equal '', body
assert_equal 'http://sinatrarb.com', response['Location']
end
end
describe 'error' do