Sha256: da199ba9672a8fea30c25283992ffdca26ef0a235715f4abecfac9019e06902e

Contents?: true

Size: 1.36 KB

Versions: 53

Compression:

Stored size: 1.36 KB

Contents

require 'ostruct'

module ExconSpecHelper

  def http_request(method, uri, options = {}, &block)
    Excon.defaults[:ssl_verify_peer] = false
    Excon.defaults[:ciphers] = 'DEFAULT'
    uri      = Addressable::URI.heuristic_parse(uri)
    uri      = uri.to_s.gsub(' ', '%20')

    excon_options = {}

    if basic_auth = options.delete(:basic_auth)
      excon_options = {user: basic_auth[0], password: basic_auth[1]}
    end

    if Gem::Version.new(Excon::VERSION) < Gem::Version.new("0.29.0")
      options  = options.merge(method: method, nonblock: false) # Dup and merge
      response = Excon.new(uri, excon_options).request(options, &block)
    else
      options  = options.merge(method: method) # Dup and merge
      response = Excon.new(uri, excon_options.merge(nonblock: false)).request(options, &block)
    end

    headers  = WebMock::Util::Headers.normalize_headers(response.headers)
    headers  = headers.inject({}) do |res, (name, value)|
      res[name] = value.is_a?(Array) ? value.flatten.join(', ') : value
      res
    end

    OpenStruct.new \
      body: response.body,
      headers: headers,
      status: response.status.to_s,
      message: response.reason_phrase
  end

  def client_timeout_exception_class
    Excon::Errors::Timeout
  end

  def connection_refused_exception_class
    Excon::Errors::SocketError
  end

  def http_library
    :excon
  end

end

Version data entries

53 entries across 47 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/webmock-3.6.0/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
webmock-3.7.4 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.7.3 spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/webmock-2.3.2/spec/acceptance/excon/excon_spec_helper.rb
webmock-3.7.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.7.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.7.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.6.2 spec/acceptance/excon/excon_spec_helper.rb