Sha256: e9fb3a5e4ff82d14cd596142f32acbd5c0feaeed77ab1040775aa54b8f5e198c

Contents?: true

Size: 1.42 KB

Versions: 90

Compression:

Stored size: 1.42 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.set_basic_auth(nil, uri.user, uri.password) if uri.user
    params = [method, "#{uri.omit(:userinfo, :query).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 = 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
    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

end

Version data entries

90 entries across 88 versions & 8 rubygems

Version Path
cloudsmith-api-2.0.16 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.15 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.14 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.7 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.6 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.5 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.4 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.2 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.1 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-2.0.0 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-1.142.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-1.120.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb
cloudsmith-api-1.61.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/spec/acceptance/httpclient/httpclient_spec_helper.rb