Sha256: ba372dba2fb133ea69f15bb171e36e1e1f9850376379db89282ed6544d1c0f6c
Contents?: true
Size: 1.1 KB
Versions: 17
Compression:
Stored size: 1.1 KB
Contents
require 'net/https' require 'uri' require 'open-uri' require 'openssl' class SiteChecker @@was_checked = false @@available = false @@site = "" @@proxy = nil class <<self def is_available? if !@@was_checked @@available = false uri = URI.parse(@@site) begin if !(proxy.nil? || proxy.empty?) proxy_uri = URI.parse(proxy) http = Net::HTTP.new(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password ) else http = Net::HTTP.new(uri.host, uri.port) end if uri.scheme == "https" # enable SSL/TLS http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.start { http.request_get(uri.path) {|res|} } @@available = true rescue => e puts "Error accessing #{uri.inspect}: #{e.inspect}" puts e.backtrace end @@was_checked = true end @@available end def site=(site) @@site = site @@was_checked = false end def site @@site end def proxy=(proxy) @@proxy = proxy @@was_checked = false end def proxy @@proxy end end end
Version data entries
17 entries across 17 versions & 2 rubygems