Class: Appium::Core::Base::Http::Default

Inherits:
Selenium::WebDriver::Remote::Http::Default
  • Object
show all
Defined in:
lib/appium_lib_core/common/base/http_default.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Accept' => CONTENT_TYPE,
  'Content-Type' => "#{CONTENT_TYPE}; charset=UTF-8",
  'User-Agent' =>
    "appium/ruby_lib_core/#{VERSION} (#{::Selenium::WebDriver::Remote::Http::Common::DEFAULT_HEADERS['User-Agent']})"
}.freeze

Instance Method Summary collapse

Instance Method Details

#call(verb, url, command_hash) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/appium_lib_core/common/base/http_default.rb', line 65

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

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

    ::Appium::Logger.info("   >>> #{url} | #{payload}")
    ::Appium::Logger.debug("     > #{headers.inspect}")
  elsif verb == :post
    payload = '{}'
    headers['Content-Length'] = '2'
  end

  request verb, url, headers, payload
end

#update_sending_request_to(scheme:, host:, port:, path:) ⇒ URI

Update server_url provided when ruby_lib _core created a default http client. Set @http as nil to re-create http client for the server_url

Parameters:

  • scheme (string)

    A scheme to update server_url to

  • host (string)

    A host to update server_url to

  • port (string|integer)

    A port number to update server_url to

  • path (string)

    A path to update server_url to

Returns:

  • (URI)

    An instance of URI updated to. Returns default ‘server_url` if some of arguments are `nil`



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appium_lib_core/common/base/http_default.rb', line 38

def update_sending_request_to(scheme:, host:, port:, path:)
  return @server_url unless validate_url_param(scheme, host, port, path)

  ::Appium::Logger.debug("[experimental] This feature, #{__method__}, is an experimental")

  # Add / if `path` does not have it
  path = path.start_with?('/') ? path : "/#{path}"
  path = path.end_with?('/') ? path : "#{path}/"

  @http = nil
  @server_url = URI.parse "#{scheme}://#{host}:#{port}#{path}"
end