Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy support for curl and wget commands #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/phantomjs.rb
Expand Up @@ -5,6 +5,8 @@ module Phantomjs
class UnknownPlatform < StandardError; end;

class << self
attr_accessor :proxy_host, :proxy_port

def available_platforms
@available_platforms ||= []
end
Expand Down
14 changes: 13 additions & 1 deletion lib/phantomjs/platform.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down