Class: ProxyFetcher::ProxyValidator
- Inherits:
-
Object
- Object
- ProxyFetcher::ProxyValidator
- Defined in:
- lib/proxy_fetcher/utils/proxy_validator.rb
Overview
Default ProxyFetcher proxy validator that checks either proxy connectable or not. It tries to send HEAD request to default URL to check if proxy can be used (aka connectable?).
Constant Summary collapse
- URL_TO_CHECK =
Default URL that will be used to check if proxy can be used.
"https://google.com"
Class Method Summary collapse
-
.connectable?(proxy_addr, proxy_port) ⇒ Boolean
Short variant to validate proxy.
Instance Method Summary collapse
-
#connectable? ⇒ Boolean
Checks if proxy is connectable (can be used to connect resources via proxy server).
-
#initialize(proxy_addr, proxy_port) ⇒ ProxyValidator
constructor
Initialize new ProxyValidator instance.
Constructor Details
#initialize(proxy_addr, proxy_port) ⇒ ProxyValidator
Initialize new ProxyValidator instance
30 31 32 33 34 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 30 def initialize(proxy_addr, proxy_port) timeout = ProxyFetcher.config.proxy_validation_timeout @http = HTTP.follow.via(proxy_addr, proxy_port.to_i).timeout(connect: timeout, read: timeout) end |
Class Method Details
.connectable?(proxy_addr, proxy_port) ⇒ Boolean
Short variant to validate proxy.
19 20 21 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 19 def self.connectable?(proxy_addr, proxy_port) new(proxy_addr, proxy_port).connectable? end |
Instance Method Details
#connectable? ⇒ Boolean
Checks if proxy is connectable (can be used to connect resources via proxy server).
42 43 44 45 46 47 48 49 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 42 def connectable? ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE @http.head(URL_TO_CHECK, ssl_context: ssl_context).status.success? rescue StandardError false end |