mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-08-10 00:01:04 -04:00
Fixes #20 Unable to handle permanent redirection, for redirects that have relative urls
This commit is contained in:
parent
63b97f7ef0
commit
151a770b87
@ -209,7 +209,13 @@ class FastImage
|
||||
if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4
|
||||
@redirect_count += 1
|
||||
begin
|
||||
@parsed_uri = URI.parse(res['Location'])
|
||||
newly_parsed_uri = URI.parse(res['Location'])
|
||||
# The new location may be relative - check for that
|
||||
if newly_parsed_uri.scheme != "http" && newly_parsed_uri.scheme != "https"
|
||||
@parsed_uri.path = res['Location']
|
||||
else
|
||||
@parsed_uri = newly_parsed_uri
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
else
|
||||
fetch_using_http_from_parsed_uri
|
||||
|
@ -186,6 +186,12 @@ class FastImageTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_should_handle_permanent_redirect_with_relative_url
|
||||
url = "http://example.nowhere/foo.jpeg"
|
||||
register_redirect(url, "/" + GoodFixtures.keys.first)
|
||||
assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(url, :raise_on_failure=>true)
|
||||
end
|
||||
|
||||
def register_redirect(from, to)
|
||||
resp = Net::HTTPMovedPermanently.new(1.0, 302, "Moved")
|
||||
resp['Location'] = to
|
||||
|
Loading…
x
Reference in New Issue
Block a user