diff --git a/lib/ssllabs/api.rb b/lib/ssllabs/api.rb index fae2f53..fe5f602 100644 --- a/lib/ssllabs/api.rb +++ b/lib/ssllabs/api.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/hash' require 'net/http' +require 'socksify/http' module Ssllabs class InvocationError < StandardError; end @@ -19,7 +20,24 @@ def initialize def request(name, params = {}) name = name.to_s.camelize(:lower) uri = URI("#{API_LOCATION}#{name}?#{URI.encode_www_form(params)}") - r = Net::HTTP.get_response(uri) + r = nil + proxy = nil + if ENV['http_proxy'] + uri_proxy = URI.parse(ENV['http_proxy']) + proxy_user, proxy_pass = nil + proxy_user, proxy_pass = uri_proxy.userinfo.split(/:/) if uri_proxy.userinfo + proxy = Net::HTTP::Proxy(uri_proxy.host,uri_proxy.port,proxy_user,proxy_pass) + elsif ENV['socks_proxy'] + uri_proxy = URI.parse(ENV['socks_proxy']) + proxy_user, proxy_pass = nil + proxy_user, proxy_pass = uri_proxy.userinfo.split(/:/) if uri_proxy.userinfo + proxy = Net::HTTP::SOCKSProxy(uri_proxy.host,uri_proxy.port) + end + if proxy.nil? + r = Net::HTTP.get_response(uri) + else + r = proxy.get_response(uri) + end if r.code.to_i == 200 @max_assessments = r['X-Max-Assessments'] @current_assessments = r['X-Current-Assessments'] diff --git a/ssllabs.gemspec b/ssllabs.gemspec index deca9c0..1f6ecf9 100644 --- a/ssllabs.gemspec +++ b/ssllabs.gemspec @@ -20,4 +20,5 @@ Gem::Specification.new do |s| s.add_dependency "activesupport", '>= 4.2.0' s.add_dependency "json", '>= 1.7' s.add_dependency "net", '~> 0.3' + s.add_dependency "socksify" end