Class: Selenium::WebDriver::Remote::Http::Default Private
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Common
|
|
|
Instance Chain:
self,
Common
|
|
| Inherits: |
Selenium::WebDriver::Remote::Http::Common
|
| Defined in: | rb/lib/selenium/webdriver/remote/http/default.rb |
Constant Summary
Common - Inherited
BINARY_ENCODINGS, CONTENT_TYPE, DEFAULT_HEADERS, MAX_REDIRECTS
Class Attribute Summary
Common - Inherited
Class Method Summary
-
.new(client_config: nil, open_timeout: nil, read_timeout: nil) ⇒ Default
constructor
Internal use only
Initializes object.
Common - Inherited
Instance Attribute Summary
- #open_timeout rw Internal use only
- #open_timeout=(value) rw Internal use only
- #proxy=(value) rw Internal use only
- #read_timeout rw Internal use only
- #read_timeout=(value) rw Internal use only
- #proxy rw private Internal use only
- #proxy_ignored? ⇒ Boolean readonly private Internal use only
- #use_proxy? ⇒ Boolean readonly private Internal use only
Common - Inherited
Instance Method Summary
- #close Internal use only
- #follow_redirect(response, redirects) private Internal use only
- #http private Internal use only
- #ip_match?(host) ⇒ Boolean private Internal use only
- #new_http_client private Internal use only
- #new_request_for(verb, url, headers, payload) private Internal use only
- #request(verb, url, headers, payload, redirects = 0) private Internal use only
- #response_for(request) private Internal use only
- #start(http) private Internal use only
Common - Inherited
| #call | steep:ignore:start. |
| #close, #quit_errors, #common_headers, #create_response, #encode_string_to_utf8, #ensure_utf8_encoding, #request | |
Constructor Details
.new(client_config: nil, open_timeout: nil, read_timeout: nil) ⇒ Default
Initializes object. Warning: Setting #open_timeout to non-nil values will cause a separate thread to spawn. Debuggers that freeze the process will not be able to evaluate any operations if that happens.
# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 33
def initialize(client_config: nil, open_timeout: nil, read_timeout: nil) if client_config && (open_timeout || read_timeout) raise ArgumentError, 'Cannot use both :client_config and :open_timeout/:read_timeout' end client_config ||= ClientConfig.new client_config.open_timeout = open_timeout if open_timeout client_config.read_timeout = read_timeout if read_timeout super(client_config: client_config) end
Instance Attribute Details
#open_timeout (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 44
def open_timeout client_config.open_timeout end
#open_timeout=(value) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 52
def open_timeout=(value) client_config.open_timeout = value end
#proxy (rw, private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 164
def proxy client_config.proxy end
#proxy=(value) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 60
def proxy=(value) client_config.proxy = value end
#proxy_ignored? ⇒ Boolean (readonly, private)
#read_timeout (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 48
def read_timeout client_config.read_timeout end
#read_timeout=(value) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 56
def read_timeout=(value) client_config.read_timeout = value end
#use_proxy? ⇒ Boolean (readonly, private)
# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 168
def use_proxy? return false if proxy.nil? return true unless proxy.no_proxy !proxy_ignored? end
Instance Method Details
#close
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 64
def close @http&.finish end
#follow_redirect(response, redirects) (private)
# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 126
def follow_redirect(response, redirects) WebDriver.logger.debug("Redirect to #{response['Location']}; times: #{redirects}") raise Error::WebDriverError, 'too many redirects' if redirects >= client_config.max_redirects request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1) end
#http (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 70
def http @http ||= begin http = new_http_client if server_url.scheme == 'https' http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.open_timeout = open_timeout if open_timeout http.read_timeout = read_timeout if read_timeout start(http) http end end
#ip_match?(host) ⇒ Boolean (private)
# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 181
def ip_match?(host) IPAddr.new(host).include?(server_url.host) rescue ArgumentError false end
#new_http_client (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 147
def new_http_client if use_proxy? url = proxy.http unless proxy.respond_to?(:http) && url raise Error::WebDriverError, "expected HTTP proxy, got #{proxy.inspect}" end proxy_uri = URI.parse(url) Net::HTTP.new(server_url.host, server_url.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) else Net::HTTP.new server_url.host, server_url.port end end
#new_request_for(verb, url, headers, payload) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 133
def new_request_for(verb, url, headers, payload) req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers) req.basic_auth server_url.user, server_url.password if server_url.userinfo req.body = payload if payload req end
#request(verb, url, headers, payload, redirects = 0) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/remote/http/default.rb', line 92
def request(verb, url, headers, payload, redirects = 0) retries = 0 begin request = new_request_for(verb, url, headers, payload) response = response_for(request) rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE, Errno::EADDRNOTAVAIL # a retry is sometimes needed: # on Windows XP where we may quickly run out of ephemeral ports # when the port becomes temporarily unavailable # # A more robust solution is bumping the MaxUserPort setting # as described here: # # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx raise if retries >= MAX_RETRIES retries += 1 sleep 2 retry rescue Errno::ECONNREFUSED => e raise e.class, "using proxy: #{proxy.http}" if use_proxy? raise end if response.is_a? Net::HTTPRedirection follow_redirect(response, redirects) else WebDriver.logger.debug(" <<< #{response.instance_variable_get(:@header).inspect}", id: :header) create_response response.code, response.body, response.content_type end end