add options[:proxy] as a per request proxy config

This commit is contained in:
Forrest Ye 2015-03-04 15:35:34 +08:00
parent 01af8e520e
commit 5ebae8ea3b
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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