diff --git a/lib/fastimage.rb b/lib/fastimage.rb index f6183f7..59efd8e 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -160,6 +160,7 @@ class FastImage def initialize(uri, options={}) @property = options[:type_only] ? :type : :size @timeout = options[:timeout] || DefaultTimeout + @proxy_url = options[:proxy] @uri = uri if uri.respond_to?(:read) @@ -259,7 +260,11 @@ class FastImage def proxy_uri begin - proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil + if @proxy_url + proxy = Addressable::URI.parse(@proxy_url) + else + proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil + end rescue Addressable::URI::InvalidURIError proxy = nil end diff --git a/test/test.rb b/test/test.rb index 3cc99a1..c5b718c 100644 --- a/test/test.rb +++ b/test/test.rb @@ -245,6 +245,13 @@ class FastImageTest < Test::Unit::TestCase assert_equal actual_size, size end + def test_should_fetch_via_proxy_option + file = "test.gif" + actual_size = GoodFixtures[file][1] + size = FastImage.size(TestUrl + file, proxy: "http://my.proxy.host:8080") + assert_equal actual_size, size + end + def test_should_handle_https_image size = FastImage.size(HTTPSImage) assert_equal HTTPSImageInfo[1], size