Sha256: 9e21ca394802bc4a66bf71b52fffc40f32fb9dd71e57f4c753e2e7c71974db8a

Contents?: true

Size: 1.45 KB

Versions: 129

Compression:

Stored size: 1.45 KB

Contents

module NetHTTPSpecHelper
  def http_request(method, uri, options = {}, &block)
    begin
      uri = URI.parse(uri)
    rescue
      uri = Addressable::URI.heuristic_parse(uri)
    end
    response = nil
    clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
    req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", nil)
    options[:headers].each do |k,v|
      if v.is_a?(Array)
        v.each_with_index do |v,i|
          i == 0 ? (req[k] = v) : req.add_field(k, v)
        end
      else
        req[k] = v
      end
    end if options[:headers]

    req.basic_auth uri.user, uri.password if uri.user
    http = Net::HTTP.new(uri.host, uri.port)
    if uri.scheme == "https"
      http.use_ssl = true
      #1.9.1 has a bug with ssl_timeout
      http.ssl_timeout = 20 unless RUBY_PLATFORM =~ /java/
      http.open_timeout = 60
      http.read_timeout = 60
    end
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    response = http.start {|http|
      http.request(req, options[:body], &block)
    }
    headers = {}
    response.each_header {|name, value| headers[name] = value}
    OpenStruct.new({
      :body => response.body,
      :headers => WebMock::Util::Headers.normalize_headers(headers),
      :status => response.code,
      :message => response.message
    })
  end

  def client_timeout_exception_class
    Timeout::Error
  end

  def connection_refused_exception_class
    Errno::ECONNREFUSED
  end

  def http_library
    :net_http
  end
end

Version data entries

129 entries across 127 versions & 11 rubygems

Version Path
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/webmock-1.24.6/spec/acceptance/net_http/net_http_spec_helper.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/webmock-1.24.6/spec/acceptance/net_http/net_http_spec_helper.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/webmock-1.24.6/spec/acceptance/net_http/net_http_spec_helper.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/webmock-1.24.6/spec/acceptance/net_http/net_http_spec_helper.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/webmock-1.24.6/spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.6 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.5 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.4 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.3 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.2 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.1 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.24.0 spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.23.0 spec/acceptance/net_http/net_http_spec_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/webmock-1.20.4/spec/acceptance/net_http/net_http_spec_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/webmock-1.20.4/spec/acceptance/net_http/net_http_spec_helper.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/webmock-1.20.4/spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.22.6 spec/acceptance/net_http/net_http_spec_helper.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/webmock-1.22.5/spec/acceptance/net_http/net_http_spec_helper.rb
webmock-1.22.5 spec/acceptance/net_http/net_http_spec_helper.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/webmock-1.22.3/spec/acceptance/net_http/net_http_spec_helper.rb