mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-10-08 00:02:41 -04:00
Merge pull request #78 from dennyac/handle-protocol-relative-uls
Handle protocol relative urls
This commit is contained in:
commit
955d77a7e9
@ -249,7 +249,9 @@ class FastImage
|
|||||||
begin
|
begin
|
||||||
newly_parsed_uri = URI.parse(res['Location'])
|
newly_parsed_uri = URI.parse(res['Location'])
|
||||||
# The new location may be relative - check for that
|
# The new location may be relative - check for that
|
||||||
if newly_parsed_uri.scheme != "http" && newly_parsed_uri.scheme != "https"
|
if protocol_relative_url?(res['Location'])
|
||||||
|
@parsed_uri = newly_parsed_uri.tap { |obj| obj.scheme = @parsed_uri.scheme }
|
||||||
|
elsif newly_parsed_uri.scheme != "http" && newly_parsed_uri.scheme != "https"
|
||||||
@parsed_uri.path = res['Location']
|
@parsed_uri.path = res['Location']
|
||||||
else
|
else
|
||||||
@parsed_uri = newly_parsed_uri
|
@parsed_uri = newly_parsed_uri
|
||||||
@ -292,6 +294,10 @@ class FastImage
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def protocol_relative_url?(url)
|
||||||
|
url.start_with?("//")
|
||||||
|
end
|
||||||
|
|
||||||
def proxy_uri
|
def proxy_uri
|
||||||
begin
|
begin
|
||||||
if @options[:proxy]
|
if @options[:proxy]
|
||||||
|
@ -235,6 +235,12 @@ class FastImageTest < Test::Unit::TestCase
|
|||||||
assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(url, :raise_on_failure=>true)
|
assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(url, :raise_on_failure=>true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_should_handle_permanent_redirect_with_protocol_relative_url
|
||||||
|
url = "http://example.nowhere/foo.jpeg"
|
||||||
|
register_redirect(url, "//example.nowhere/" + GoodFixtures.keys.first)
|
||||||
|
assert_equal GoodFixtures[GoodFixtures.keys.first][1], FastImage.size(url, :raise_on_failure=>true)
|
||||||
|
end
|
||||||
|
|
||||||
def register_redirect(from, to)
|
def register_redirect(from, to)
|
||||||
resp = Net::HTTPMovedPermanently.new(1.0, 302, "Moved")
|
resp = Net::HTTPMovedPermanently.new(1.0, 302, "Moved")
|
||||||
resp['Location'] = to
|
resp['Location'] = to
|
||||||
|
Loading…
x
Reference in New Issue
Block a user