From 4b4e59feabd7142195dad4cc60d8f0261977b6cd Mon Sep 17 00:00:00 2001 From: Mikhail Grachev Date: Wed, 22 Jul 2015 23:29:21 +0300 Subject: [PATCH] Add proxy support for curl and wget commands --- lib/phantomjs.rb | 2 ++ lib/phantomjs/platform.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/phantomjs.rb b/lib/phantomjs.rb index 54c9adb..c6df97a 100644 --- a/lib/phantomjs.rb +++ b/lib/phantomjs.rb @@ -5,6 +5,8 @@ module Phantomjs class UnknownPlatform < StandardError; end; class << self + attr_accessor :proxy_host, :proxy_port + def available_platforms @available_platforms ||= [] end diff --git a/lib/phantomjs/platform.rb b/lib/phantomjs/platform.rb index 822c0fb..297fc90 100644 --- a/lib/phantomjs/platform.rb +++ b/lib/phantomjs/platform.rb @@ -51,7 +51,7 @@ def install! FileUtils.mkdir_p temp_dir Dir.chdir temp_dir do - unless system "curl -L -O #{package_url}" or system "wget #{package_url}" + unless system "curl -L -O #{package_url} #{curl_proxy_options}" or system "wget #{package_url} #{wget_proxy_options}" raise "\n\nFailed to load phantomjs! :(\nYou need to have cURL or wget installed on your system.\nIf you have, the source of phantomjs might be unavailable: #{package_url}\n\n" end @@ -85,6 +85,18 @@ def install! def ensure_installed! install! unless installed? end + + private + + def curl_proxy_options + return '' if Phantomjs.proxy_host.nil? && Phantomjs.proxy_port.nil? + "-x #{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}" + end + + def wget_proxy_options + return '' if Phantomjs.proxy_host.nil? && Phantomjs.proxy_port.nil? + "-e use_proxy=yes -e http_proxy=#{Phantomjs.proxy_host}:#{Phantomjs.proxy_port}" + end end class Linux64 < Platform