External Typhoeus Adapter Compatibility (#748)

This commit is contained in:
Mattia 2017-11-17 09:54:24 +00:00 committed by GitHub
parent 53b5e087e9
commit b302d708ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 0 deletions

View File

@ -21,6 +21,7 @@ group :test do
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
gem 'simplecov'
gem 'sinatra', '~> 1.3'
gem 'typhoeus', '~> 1.3', :require => 'typhoeus'
end
gemspec

View File

@ -8,6 +8,7 @@ module Faraday
:test => [:Test, 'test'],
:net_http => [:NetHttp, 'net_http'],
:net_http_persistent => [:NetHttpPersistent, 'net_http_persistent'],
:typhoeus => [:Typhoeus, 'typhoeus'],
:patron => [:Patron, 'patron'],
:em_synchrony => [:EMSynchrony, 'em_synchrony'],
:em_http => [:EMHttp, 'em_http'],

View File

@ -0,0 +1,12 @@
module Faraday
class Adapter
# This class is just a stub, the real adapter is in https://github.com/philsturgeon/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb
class Typhoeus < Faraday::Adapter
# Needs to define this method in order to support Typhoeus <= 1.3.0
def call; end
dependency 'typhoeus'
dependency 'typhoeus/adapters/faraday'
end
end
end

View File

@ -55,6 +55,7 @@ module Faraday
:NetHttpPersistent => 'net_http_persistent',
:EMSynchrony => 'em_synchrony',
:EMHttp => 'em_http',
:Typhoeus => 'typhoeus',
:Patron => 'patron',
:Excon => 'excon',
:Test => 'test',

View File

@ -0,0 +1,38 @@
require File.expand_path('../integration', __FILE__)
module Adapters
class TyphoeusTest < Faraday::TestCase
def adapter() :typhoeus end
Integration.apply(self, :Parallel) do
# inconsistent outcomes ranging from successful response to connection error
undef :test_proxy_auth_fail if ssl_mode?
# Typhoeus adapter not supporting Faraday::SSLError
undef :test_GET_ssl_fails_with_bad_cert if ssl_mode?
def test_binds_local_socket
host = '1.2.3.4'
conn = create_connection :request => { :bind => { :host => host } }
assert_equal host, conn.options[:bind][:host]
end
# Typhoeus::Response doesn't provide an easy way to access the reason phrase,
# so override the shared test from Common.
def test_GET_reason_phrase
response = get('echo')
assert_nil response.reason_phrase
end
end
def test_custom_adapter_config
adapter = Faraday::Adapter::Typhoeus.new(nil, { :forbid_reuse => true, :maxredirs => 1 })
request = adapter.method(:typhoeus_request).call({})
assert_equal true, request.options[:forbid_reuse]
assert_equal 1, request.options[:maxredirs]
end
end
end