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?(address, 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(address, port, options: {}) ⇒ ProxyValidator
constructor
Initialize new ProxyValidator instance.
Constructor Details
#initialize(address, port, options: {}) ⇒ ProxyValidator
Initialize new ProxyValidator instance
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 34 def initialize(address, port, options: {}) timeout = ProxyFetcher.config.proxy_validation_timeout proxy = [address, port.to_i] if [:username] && [:password] proxy << [:username] proxy << [:password] end proxy << [:headers].to_h if [:headers] @http = HTTP.follow.via(*proxy).timeout(connect: timeout, read: timeout) end |
Class Method Details
.connectable?(address, port) ⇒ Boolean
Short variant to validate proxy.
19 20 21 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 19 def self.connectable?(address, port) new(address, port).connectable? end |
Instance Method Details
#connectable? ⇒ Boolean
Checks if proxy is connectable (can be used to connect resources via proxy server).
54 55 56 57 58 59 60 61 |
# File 'lib/proxy_fetcher/utils/proxy_validator.rb', line 54 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 |