Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Add proxy support -- socks & http #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/ssllabs/api.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support/core_ext/hash'
require 'net/http'
require 'socksify/http'

module Ssllabs
class InvocationError < StandardError; end
Expand All @@ -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']
Expand Down
1 change: 1 addition & 0 deletions ssllabs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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