Class: ProxyFetcher::ProxyValidator
- Inherits:
-
Object
- Object
- ProxyFetcher::ProxyValidator
- Defined in:
- lib/proxy_fetcher/utils/proxy_validator.rb
Constant Summary collapse
- URL_TO_CHECK =
'https://google.com'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #connectable? ⇒ Boolean
-
#initialize(proxy_addr, proxy_port) ⇒ ProxyValidator
constructor
A new instance of ProxyValidator.
Constructor Details
#initialize(proxy_addr, proxy_port) ⇒ ProxyValidator
Returns a new instance of ProxyValidator.
5 6 7 8 9 10 11 12 13 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 5 def initialize(proxy_addr, proxy_port) uri = URI.parse(URL_TO_CHECK) @http = Net::HTTP.new(uri.host, uri.port, proxy_addr, proxy_port.to_i) return unless uri.is_a?(URI::HTTPS) @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Class Method Details
.connectable?(proxy_addr, proxy_port) ⇒ Boolean
27 28 29 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 27 def connectable?(proxy_addr, proxy_port) new(proxy_addr, proxy_port).connectable? end |
Instance Method Details
#connectable? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 15 def connectable? @http.open_timeout = ProxyFetcher.config.timeout @http.read_timeout = ProxyFetcher.config.timeout @http.start { |connection| return true if connection.request_head('/') } false rescue StandardError false end |