Class: Selenium::WebDriver::Remote::Http::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/remote/http/common.rb

Direct Known Subclasses

Curb, Default

Constant Summary collapse

MAX_REDIRECTS =

same as chromium/gecko

20
CONTENT_TYPE =
'application/json'
DEFAULT_HEADERS =
{
  'Accept' => CONTENT_TYPE,
  'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8"
}.freeze
BINARY_ENCODINGS =
[Encoding::BINARY, Encoding::ASCII_8BIT].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_config: nil) ⇒ Common

Returns a new instance of Common.



53
54
55
# File 'lib/selenium/webdriver/remote/http/common.rb', line 53

def initialize(client_config: nil)
  @client_config = client_config || ClientConfig.new
end

Instance Attribute Details

#client_configObject (readonly)

Returns the value of attribute client_config.



51
52
53
# File 'lib/selenium/webdriver/remote/http/common.rb', line 51

def client_config
  @client_config
end

Class Method Details

.extra_headersObject



42
43
44
# File 'lib/selenium/webdriver/remote/http/common.rb', line 42

def extra_headers
  ClientConfig.default_extra_headers
end

.extra_headers=(value) ⇒ Object



46
47
48
# File 'lib/selenium/webdriver/remote/http/common.rb', line 46

def extra_headers=(value)
  ClientConfig.default_extra_headers = value
end

.user_agentObject



34
35
36
# File 'lib/selenium/webdriver/remote/http/common.rb', line 34

def user_agent
  ClientConfig.default_user_agent
end

.user_agent=(value) ⇒ Object



38
39
40
# File 'lib/selenium/webdriver/remote/http/common.rb', line 38

def user_agent=(value)
  ClientConfig.default_user_agent = value
end

Instance Method Details

#call(verb, url, command_hash) ⇒ Object

steep:ignore:start



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/selenium/webdriver/remote/http/common.rb', line 70

def call(verb, url, command_hash)
  url      = server_url.merge(url) unless url.is_a?(URI)
  headers  = common_headers.dup
  headers['Cache-Control'] = 'no-cache' if verb == :get

  if command_hash
    command_hash              = ensure_utf8_encoding(command_hash)
    payload                   = JSON.generate(command_hash)
    headers['Content-Length'] = payload.bytesize.to_s if %i[post put].include?(verb)

    WebDriver.logger.debug("   >>> #{url} | #{payload}", id: :command)
    WebDriver.logger.debug("     > #{headers.inspect}", id: :header)
  elsif verb == :post
    payload = '{}'
    headers['Content-Length'] = '2'
  end

  request verb, url, headers, payload
end

#closeObject



65
66
67
# File 'lib/selenium/webdriver/remote/http/common.rb', line 65

def close
  # hook for subclasses - will be called on Driver#quit
end

#quit_errorsObject



61
62
63
# File 'lib/selenium/webdriver/remote/http/common.rb', line 61

def quit_errors
  [IOError]
end

#server_url=(url) ⇒ Object



57
58
59
# File 'lib/selenium/webdriver/remote/http/common.rb', line 57

def server_url=(url)
  client_config.server_url = url
end