mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-08-10 00:01:04 -04:00
Use proxy if it exists
This commit is contained in:
parent
10bbbee0b9
commit
93a8b313c2
@ -206,8 +206,24 @@ class FastImage
|
||||
end
|
||||
end
|
||||
|
||||
def proxy_uri
|
||||
begin
|
||||
proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? URI.parse(ENV['http_proxy']) : nil
|
||||
rescue URI::InvalidURIError
|
||||
proxy = nil
|
||||
end
|
||||
proxy
|
||||
end
|
||||
|
||||
def setup_http
|
||||
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
|
||||
proxy = proxy_uri
|
||||
|
||||
if proxy
|
||||
@http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.port)
|
||||
else
|
||||
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
|
||||
end
|
||||
|
||||
@http.use_ssl = (@parsed_uri.scheme == "https")
|
||||
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
@http.open_timeout = @timeout
|
||||
|
12
test/test.rb
12
test/test.rb
@ -191,4 +191,16 @@ class FastImageTest < Test::Unit::TestCase
|
||||
assert type_time - time < LargeImageFetchLimit
|
||||
assert_equal LargeImageInfo[0], type
|
||||
end
|
||||
|
||||
# This test doesn't actually test the proxy function, but at least
|
||||
# it excercises the code. You could put anything in the http_proxy and it would still pass.
|
||||
# Any ideas on how to actually test this?
|
||||
def test_should_fetch_via_proxy
|
||||
file = "test.gif"
|
||||
actual_size = GoodFixtures[file][1]
|
||||
ENV['http_proxy'] = "http://my.proxy.host:8080"
|
||||
size = FastImage.size(TestUrl + file)
|
||||
ENV['http_proxy'] = nil
|
||||
assert_equal actual_size, size
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user