Sha256: 50f5e2fdffc72bbd1bb2ddd3f1d2cb364b194ceb59aa4f1cdc015c1bf5ac3bde

Contents?: true

Size: 1.4 KB

Versions: 51

Compression:

Stored size: 1.4 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

    Excon.set_raise_on_warnings!(true)

    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

51 entries across 51 versions & 4 rubygems

Version Path
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/excon/excon_spec_helper.rb
webmock-3.13.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.12.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.12.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.12.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.11.3 spec/acceptance/excon/excon_spec_helper.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.11.2/spec/acceptance/excon/excon_spec_helper.rb
webmock-3.11.2 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.11.1 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.11.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.10.0 spec/acceptance/excon/excon_spec_helper.rb
webmock-3.9.5 spec/acceptance/excon/excon_spec_helper.rb