lib/censys/api.rb in censu-0.1.3 vs lib/censys/api.rb in censu-0.1.4

- old
+ new

@@ -202,10 +202,29 @@ def url_for(path) URI(URL + path) end # + # Return HTTPS options + # + # @return [Hash] + # + def https_options + if proxy = ENV["HTTPS_PROXY"] + uri = URI(proxy) + { + proxy_address: uri.hostname, + proxy_port: uri.port, + proxy_from_env: false, + use_ssl: true + } + else + { use_ssl: true } + end + end + + # # Sends the HTTP request and handles the response. # # @param [Net::HTTP::Get, Net::HTTP::Post] req # The prepared request to send. # @@ -218,10 +237,10 @@ # @raise [NotFound, RateLimited, InternalServerError, ResponseError] # If an error response is returned, the appropriate exception will be # raised. # def request(req) - Net::HTTP.start(HOST, 443, use_ssl: true) do |http| + Net::HTTP.start(HOST, 443, https_options) do |http| response = http.request(req) case response.code when '200' then yield JSON.parse(response.body) when '302' then raise(AuthenticationError, response.body)