mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-10-06 00:02:01 -04:00
add options[:proxy] as a per request proxy config
This commit is contained in:
parent
01af8e520e
commit
5ebae8ea3b
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user