mirror of
https://github.com/lostisland/faraday.git
synced 2025-11-22 00:08:56 -05:00
Remove Typhoeus adapter (#715)
This commit is contained in:
parent
2b580148fd
commit
e63ef9b830
@ -12,7 +12,7 @@ $ script/bootstrap
|
||||
$ script/test
|
||||
|
||||
# run only specific files
|
||||
$ script/test excon typhoeus
|
||||
$ script/test excon patron
|
||||
|
||||
# run tests using SSL
|
||||
$ SSL=yes script/test
|
||||
|
||||
1
Gemfile
1
Gemfile
@ -21,7 +21,6 @@ group :test do
|
||||
gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
|
||||
gem 'simplecov'
|
||||
gem 'sinatra', '~> 1.3'
|
||||
gem 'typhoeus', '~> 0.3.3', :platforms => [:ruby_18, :ruby_19, :ruby_20, :ruby_21]
|
||||
end
|
||||
|
||||
gemspec
|
||||
|
||||
@ -8,7 +8,6 @@ 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'],
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
module Faraday
|
||||
class Adapter
|
||||
class Typhoeus < Faraday::Adapter
|
||||
self.supports_parallel = true
|
||||
|
||||
def self.setup_parallel_manager(options = {})
|
||||
options.empty? ? ::Typhoeus::Hydra.hydra : ::Typhoeus::Hydra.new(options)
|
||||
end
|
||||
|
||||
dependency 'typhoeus'
|
||||
|
||||
def call(env)
|
||||
super
|
||||
perform_request env
|
||||
@app.call env
|
||||
end
|
||||
|
||||
def perform_request(env)
|
||||
read_body env
|
||||
|
||||
hydra = env[:parallel_manager] || self.class.setup_parallel_manager
|
||||
hydra.queue request(env)
|
||||
hydra.run unless parallel?(env)
|
||||
rescue Errno::ECONNREFUSED
|
||||
raise Error::ConnectionFailed, $!
|
||||
end
|
||||
|
||||
# TODO: support streaming requests
|
||||
def read_body(env)
|
||||
env[:body] = env[:body].read if env[:body].respond_to? :read
|
||||
end
|
||||
|
||||
def request(env)
|
||||
method = env[:method]
|
||||
# For some reason, prevents Typhoeus from using "100-continue".
|
||||
# We want this because Webrick 1.3.1 can't seem to handle it w/ PUT.
|
||||
method = method.to_s.upcase if method == :put
|
||||
|
||||
req = ::Typhoeus::Request.new env[:url].to_s,
|
||||
:method => method,
|
||||
:body => env[:body],
|
||||
:headers => env[:request_headers],
|
||||
:disable_ssl_peer_verification => (env[:ssl] && env[:ssl].disable?)
|
||||
|
||||
configure_ssl req, env
|
||||
configure_proxy req, env
|
||||
configure_timeout req, env
|
||||
configure_socket req, env
|
||||
|
||||
req.on_complete do |resp|
|
||||
if resp.timed_out?
|
||||
if parallel?(env)
|
||||
# TODO: error callback in async mode
|
||||
else
|
||||
raise Faraday::Error::TimeoutError, "request timed out"
|
||||
end
|
||||
end
|
||||
|
||||
case resp.curl_return_code
|
||||
when 0
|
||||
# everything OK
|
||||
when 7
|
||||
raise Error::ConnectionFailed, resp.curl_error_message
|
||||
when 60
|
||||
raise Faraday::SSLError, resp.curl_error_message
|
||||
else
|
||||
raise Error::ClientError, resp.curl_error_message
|
||||
end
|
||||
|
||||
save_response(env, resp.code, resp.body) do |response_headers|
|
||||
response_headers.parse resp.headers
|
||||
end
|
||||
# in async mode, :response is initialized at this point
|
||||
env[:response].finish(env) if parallel?(env)
|
||||
end
|
||||
|
||||
req
|
||||
end
|
||||
|
||||
def configure_ssl(req, env)
|
||||
ssl = env[:ssl]
|
||||
|
||||
req.ssl_version = ssl[:version] if ssl[:version]
|
||||
req.ssl_cert = ssl[:client_cert] if ssl[:client_cert]
|
||||
req.ssl_key = ssl[:client_key] if ssl[:client_key]
|
||||
req.ssl_cacert = ssl[:ca_file] if ssl[:ca_file]
|
||||
req.ssl_capath = ssl[:ca_path] if ssl[:ca_path]
|
||||
end
|
||||
|
||||
def configure_proxy(req, env)
|
||||
proxy = request_options(env)[:proxy]
|
||||
return unless proxy
|
||||
|
||||
req.proxy = "#{proxy[:uri].host}:#{proxy[:uri].port}"
|
||||
|
||||
if proxy[:user] && proxy[:password]
|
||||
req.proxy_username = proxy[:user]
|
||||
req.proxy_password = proxy[:password]
|
||||
end
|
||||
end
|
||||
|
||||
def configure_timeout(req, env)
|
||||
env_req = request_options(env)
|
||||
req.timeout = req.connect_timeout = (env_req[:timeout] * 1000) if env_req[:timeout]
|
||||
req.connect_timeout = (env_req[:open_timeout] * 1000) if env_req[:open_timeout]
|
||||
end
|
||||
|
||||
def configure_socket(req, env)
|
||||
if bind = request_options(env)[:bind]
|
||||
req.interface = bind[:host]
|
||||
end
|
||||
end
|
||||
|
||||
def request_options(env)
|
||||
env[:request]
|
||||
end
|
||||
|
||||
def parallel?(env)
|
||||
!!env[:parallel_manager]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -53,7 +53,6 @@ module Faraday
|
||||
autoload_all 'faraday/adapter',
|
||||
:NetHttp => 'net_http',
|
||||
:NetHttpPersistent => 'net_http_persistent',
|
||||
:Typhoeus => 'typhoeus',
|
||||
:EMSynchrony => 'em_synchrony',
|
||||
:EMHttp => 'em_http',
|
||||
:Patron => 'patron',
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#
|
||||
# $ script/test
|
||||
# $ script/test test/env_test.rb
|
||||
# $ script/test excon typhoeus
|
||||
# $ script/test excon patron
|
||||
#
|
||||
# # Run only tests matching /ssl/ for the net_http adapter, with SSL enabled.
|
||||
# $ SSL=yes script/test net_http -- -n /ssl/
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
require File.expand_path('../integration', __FILE__)
|
||||
|
||||
module Adapters
|
||||
class TyphoeusTest < Faraday::TestCase
|
||||
|
||||
def adapter() :typhoeus end
|
||||
|
||||
Integration.apply(self, :Parallel) do
|
||||
# https://github.com/dbalatero/typhoeus/issues/75
|
||||
undef :test_GET_with_body
|
||||
|
||||
# Not a Typhoeus bug, but WEBrick inability to handle "100-continue"
|
||||
# which libcurl seems to generate for this particular request:
|
||||
undef :test_POST_sends_files
|
||||
|
||||
# inconsistent outcomes ranging from successful response to connection error
|
||||
undef :test_proxy_auth_fail if ssl_mode?
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
end unless jruby? or ruby_22_plus?
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user