Sha256: f9832e63015af05af88a504fd2cb87f74fd521325f4da5df511163a8fef5f14e

Contents?: true

Size: 1.55 KB

Versions: 102

Compression:

Stored size: 1.55 KB

Contents

module HTTPClientSpecHelper
  class << self
    attr_accessor :async_mode
  end

  def http_request(method, uri, options = {}, &block)
    uri = Addressable::URI.heuristic_parse(uri)
    c = options.fetch(:client) { HTTPClient.new }
    c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
    c.reset_all
    if options[:basic_auth]
      c.force_basic_auth = true
      c.set_basic_auth(nil, options[:basic_auth][0], options[:basic_auth][1])
    end
    params = [method, uri.normalize.to_s,
      WebMock::Util::QueryMapper.query_to_values(uri.query, notation: WebMock::Config.instance.query_values_notation), options[:body], options[:headers] || {}]
    if HTTPClientSpecHelper.async_mode
      connection = c.request_async(*params)
      connection.join
      response = connection.pop
    else
      response = c.request(*params, &block)
    end
    headers = merge_headers(response)
    OpenStruct.new({
      body: HTTPClientSpecHelper.async_mode ? response.content.read : response.content,
      headers: headers,
      status: response.code.to_s,
      message: response.reason
    })
  end

  def client_timeout_exception_class
    HTTPClient::TimeoutError
  end

  def connection_refused_exception_class
    Errno::ECONNREFUSED
  end

  def http_library
    :httpclient
  end

private

  def merge_headers(response)
    response.header.all.inject({}) do |headers, header|
      if !headers.has_key?(header[0])
        headers[header[0]] = header[1]
      else
        headers[header[0]] = [headers[header[0]], header[1]].join(', ')
      end
      headers
    end
  end
end

Version data entries

102 entries across 96 versions & 8 rubygems

Version Path
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.13.0 spec/acceptance/httpclient/httpclient_spec_helper.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/webmock-2.3.2/spec/acceptance/httpclient/httpclient_spec_helper.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.12.2 spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.12.1 spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.12.0 spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.11.3 spec/acceptance/httpclient/httpclient_spec_helper.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.11.2/spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.11.2 spec/acceptance/httpclient/httpclient_spec_helper.rb
webmock-3.11.1 spec/acceptance/httpclient/httpclient_spec_helper.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/webmock-2.3.2/spec/acceptance/httpclient/httpclient_spec_helper.rb