faraday 1.2.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +104 -0
- data/README.md +1 -2
- data/lib/faraday.rb +7 -1
- data/lib/faraday/adapter.rb +0 -8
- data/lib/faraday/autoload.rb +0 -5
- data/lib/faraday/connection.rb +8 -1
- data/lib/faraday/error.rb +12 -0
- data/lib/faraday/options/proxy_options.rb +4 -0
- data/lib/faraday/request/retry.rb +1 -1
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/connection_spec.rb +38 -0
- data/spec/faraday/error_spec.rb +15 -0
- data/spec/faraday/options/proxy_options_spec.rb +7 -0
- data/spec/faraday/response/raise_error_spec.rb +30 -0
- metadata +76 -14
- data/lib/faraday/adapter/em_http.rb +0 -289
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
- data/lib/faraday/adapter/em_synchrony.rb +0 -153
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
- data/lib/faraday/adapter/excon.rb +0 -124
- data/lib/faraday/adapter/net_http.rb +0 -220
- data/lib/faraday/adapter/net_http_persistent.rb +0 -91
- data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Adapter
|
5
|
-
# Net::HTTP::Persistent adapter.
|
6
|
-
class NetHttpPersistent < NetHttp
|
7
|
-
dependency 'net/http/persistent'
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def net_http_connection(env)
|
12
|
-
@cached_connection ||=
|
13
|
-
if Net::HTTP::Persistent.instance_method(:initialize)
|
14
|
-
.parameters.first == %i[key name]
|
15
|
-
options = { name: 'Faraday' }
|
16
|
-
if @connection_options.key?(:pool_size)
|
17
|
-
options[:pool_size] = @connection_options[:pool_size]
|
18
|
-
end
|
19
|
-
Net::HTTP::Persistent.new(**options)
|
20
|
-
else
|
21
|
-
Net::HTTP::Persistent.new('Faraday')
|
22
|
-
end
|
23
|
-
|
24
|
-
proxy_uri = proxy_uri(env)
|
25
|
-
if @cached_connection.proxy_uri != proxy_uri
|
26
|
-
@cached_connection.proxy = proxy_uri
|
27
|
-
end
|
28
|
-
@cached_connection
|
29
|
-
end
|
30
|
-
|
31
|
-
def proxy_uri(env)
|
32
|
-
proxy_uri = nil
|
33
|
-
if (proxy = env[:request][:proxy])
|
34
|
-
proxy_uri = if proxy[:uri].is_a?(::URI::HTTP)
|
35
|
-
proxy[:uri].dup
|
36
|
-
else
|
37
|
-
::URI.parse(proxy[:uri].to_s)
|
38
|
-
end
|
39
|
-
proxy_uri.user = proxy_uri.password = nil
|
40
|
-
# awful patch for net-http-persistent 2.8
|
41
|
-
# not unescaping user/password
|
42
|
-
if proxy[:user]
|
43
|
-
(class << proxy_uri; self; end).class_eval do
|
44
|
-
define_method(:user) { proxy[:user] }
|
45
|
-
define_method(:password) { proxy[:password] }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
proxy_uri
|
50
|
-
end
|
51
|
-
|
52
|
-
def perform_request(http, env)
|
53
|
-
http.request env[:url], create_request(env)
|
54
|
-
rescue Errno::ETIMEDOUT => e
|
55
|
-
raise Faraday::TimeoutError, e
|
56
|
-
rescue Net::HTTP::Persistent::Error => e
|
57
|
-
raise Faraday::TimeoutError, e if e.message.include? 'Timeout'
|
58
|
-
|
59
|
-
if e.message.include? 'connection refused'
|
60
|
-
raise Faraday::ConnectionFailed, e
|
61
|
-
end
|
62
|
-
|
63
|
-
raise
|
64
|
-
end
|
65
|
-
|
66
|
-
SSL_CONFIGURATIONS = {
|
67
|
-
certificate: :client_cert,
|
68
|
-
private_key: :client_key,
|
69
|
-
ca_file: :ca_file,
|
70
|
-
ssl_version: :version,
|
71
|
-
min_version: :min_version,
|
72
|
-
max_version: :max_version
|
73
|
-
}.freeze
|
74
|
-
|
75
|
-
def configure_ssl(http, ssl)
|
76
|
-
return unless ssl
|
77
|
-
|
78
|
-
http_set(http, :verify_mode, ssl_verify_mode(ssl))
|
79
|
-
http_set(http, :cert_store, ssl_cert_store(ssl))
|
80
|
-
|
81
|
-
SSL_CONFIGURATIONS
|
82
|
-
.select { |_, key| ssl[key] }
|
83
|
-
.each { |target, key| http_set(http, target, ssl[key]) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def http_set(http, attr, value)
|
87
|
-
http.send("#{attr}=", value) if http.send(attr) != value
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Faraday::Adapter::NetHttpPersistent do
|
4
|
-
features :request_body_on_query_methods, :reason_phrase_parse, :compression, :trace_method
|
5
|
-
|
6
|
-
it_behaves_like 'an adapter'
|
7
|
-
|
8
|
-
it 'allows to provide adapter specific configs' do
|
9
|
-
url = URI('https://example.com')
|
10
|
-
|
11
|
-
adapter = described_class.new do |http|
|
12
|
-
http.idle_timeout = 123
|
13
|
-
end
|
14
|
-
|
15
|
-
http = adapter.send(:connection, url: url, request: {})
|
16
|
-
adapter.send(:configure_request, http, {})
|
17
|
-
|
18
|
-
expect(http.idle_timeout).to eq(123)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'sets max_retries to 0' do
|
22
|
-
url = URI('http://example.com')
|
23
|
-
|
24
|
-
adapter = described_class.new
|
25
|
-
|
26
|
-
http = adapter.send(:connection, url: url, request: {})
|
27
|
-
adapter.send(:configure_request, http, {})
|
28
|
-
|
29
|
-
# `max_retries=` is only present in Ruby 2.5
|
30
|
-
expect(http.max_retries).to eq(0) if http.respond_to?(:max_retries=)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'allows to set pool_size on initialize' do
|
34
|
-
url = URI('https://example.com')
|
35
|
-
|
36
|
-
adapter = described_class.new(nil, pool_size: 5)
|
37
|
-
|
38
|
-
http = adapter.send(:connection, url: url, request: {})
|
39
|
-
|
40
|
-
# `pool` is only present in net_http_persistent >= 3.0
|
41
|
-
expect(http.pool.size).to eq(5) if http.respond_to?(:pool)
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'min_version' do
|
45
|
-
it 'allows to set min_version in SSL settings' do
|
46
|
-
url = URI('https://example.com')
|
47
|
-
|
48
|
-
adapter = described_class.new(nil)
|
49
|
-
|
50
|
-
http = adapter.send(:connection, url: url, request: {})
|
51
|
-
adapter.send(:configure_ssl, http, min_version: :TLS1_2)
|
52
|
-
|
53
|
-
# `min_version` is only present in net_http_persistent >= 3.1 (UNRELEASED)
|
54
|
-
expect(http.min_version).to eq(:TLS1_2) if http.respond_to?(:min_version)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|