From 3365eb88ed2e24bca75bc0a2198930f4ba97d4b8 Mon Sep 17 00:00:00 2001 From: lionel Date: Mon, 6 Feb 2017 09:58:02 +0100 Subject: [PATCH 1/2] Add proxy support -- socks & http --- lib/ssllabs/api.rb | 20 +++++++++++++++++++- ssllabs.gemspec | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/ssllabs/api.rb b/lib/ssllabs/api.rb index fae2f53..8f7db78 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,proxy_user,proxy_pass) + 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 From 801e21fc353a166a4e824786ec085f68bbbdef70 Mon Sep 17 00:00:00 2001 From: Lionel Date: Thu, 9 Feb 2017 17:47:24 +0100 Subject: [PATCH 2/2] Update api.rb --- lib/ssllabs/api.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ssllabs/api.rb b/lib/ssllabs/api.rb index 8f7db78..fe5f602 100644 --- a/lib/ssllabs/api.rb +++ b/lib/ssllabs/api.rb @@ -31,7 +31,7 @@ def request(name, params = {}) 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,proxy_user,proxy_pass) + proxy = Net::HTTP::SOCKSProxy(uri_proxy.host,uri_proxy.port) end if proxy.nil? r = Net::HTTP.get_response(uri)