faraday 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -1
- data/lib/faraday.rb +2 -0
- data/lib/faraday/adapter.rb +0 -5
- data/lib/faraday/autoload.rb +0 -2
- data/lib/faraday/version.rb +1 -1
- metadata +30 -5
- data/lib/faraday/adapter/excon.rb +0 -124
- data/lib/faraday/adapter/net_http_persistent.rb +0 -91
- data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9232bd1a6a03e460d5959725591c2aeae3094f3e29a48dadcf9531ee878d61b2
|
4
|
+
data.tar.gz: 261fa4b48f2eb5633abc5352f30965693e8b0b283c7204645ad0ea562d82d3ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d707ade012eacb6eb017365b18778ad8553cec5f27a8571331ab5b3bc388605f0b8692de98c1ab36c60528dfbcd2cfe0e12b0bdec343240721dd08f16d4fd376
|
7
|
+
data.tar.gz: 86fef1e9db15dcb666b9255d1f5aea529aa2c2a51fe0cdd7ca011f00870299c2200d6b200d801516269281f2b524248670b40bb0ca57d130358a2383e7e50f01
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
|
4
4
|
[![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/f869daab091ceef1da73/maintainability)](https://codeclimate.com/github/lostisland/faraday/maintainability)
|
6
5
|
[![Gitter](https://badges.gitter.im/lostisland/faraday.svg)](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
7
6
|
|
8
7
|
|
data/lib/faraday.rb
CHANGED
data/lib/faraday/adapter.rb
CHANGED
@@ -11,15 +11,10 @@ module Faraday
|
|
11
11
|
|
12
12
|
register_middleware File.expand_path('adapter', __dir__),
|
13
13
|
test: [:Test, 'test'],
|
14
|
-
net_http_persistent: [
|
15
|
-
:NetHttpPersistent,
|
16
|
-
'net_http_persistent'
|
17
|
-
],
|
18
14
|
typhoeus: [:Typhoeus, 'typhoeus'],
|
19
15
|
patron: [:Patron, 'patron'],
|
20
16
|
em_synchrony: [:EMSynchrony, 'em_synchrony'],
|
21
17
|
em_http: [:EMHttp, 'em_http'],
|
22
|
-
excon: [:Excon, 'excon'],
|
23
18
|
rack: [:Rack, 'rack'],
|
24
19
|
httpclient: [:HTTPClient, 'httpclient']
|
25
20
|
|
data/lib/faraday/autoload.rb
CHANGED
@@ -58,12 +58,10 @@ module Faraday
|
|
58
58
|
class Adapter
|
59
59
|
extend AutoloadHelper
|
60
60
|
autoload_all 'faraday/adapter',
|
61
|
-
NetHttpPersistent: 'net_http_persistent',
|
62
61
|
EMSynchrony: 'em_synchrony',
|
63
62
|
EMHttp: 'em_http',
|
64
63
|
Typhoeus: 'typhoeus',
|
65
64
|
Patron: 'patron',
|
66
|
-
Excon: 'excon',
|
67
65
|
Test: 'test',
|
68
66
|
Rack: 'rack',
|
69
67
|
HTTPClient: 'httpclient'
|
data/lib/faraday/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -12,6 +12,20 @@ bindir: bin
|
|
12
12
|
cert_chain: []
|
13
13
|
date: 2021-04-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: faraday-excon
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.0'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: faraday-net_http
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -26,6 +40,20 @@ dependencies:
|
|
26
40
|
- - "~>"
|
27
41
|
- !ruby/object:Gem::Version
|
28
42
|
version: '1.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: faraday-net_http_persistent
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.0'
|
29
57
|
- !ruby/object:Gem::Dependency
|
30
58
|
name: multipart-post
|
31
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,9 +106,7 @@ files:
|
|
78
106
|
- lib/faraday/adapter/em_http_ssl_patch.rb
|
79
107
|
- lib/faraday/adapter/em_synchrony.rb
|
80
108
|
- lib/faraday/adapter/em_synchrony/parallel_manager.rb
|
81
|
-
- lib/faraday/adapter/excon.rb
|
82
109
|
- lib/faraday/adapter/httpclient.rb
|
83
|
-
- lib/faraday/adapter/net_http_persistent.rb
|
84
110
|
- lib/faraday/adapter/patron.rb
|
85
111
|
- lib/faraday/adapter/rack.rb
|
86
112
|
- lib/faraday/adapter/test.rb
|
@@ -126,7 +152,6 @@ files:
|
|
126
152
|
- spec/faraday/adapter/em_synchrony_spec.rb
|
127
153
|
- spec/faraday/adapter/excon_spec.rb
|
128
154
|
- spec/faraday/adapter/httpclient_spec.rb
|
129
|
-
- spec/faraday/adapter/net_http_persistent_spec.rb
|
130
155
|
- spec/faraday/adapter/net_http_spec.rb
|
131
156
|
- spec/faraday/adapter/patron_spec.rb
|
132
157
|
- spec/faraday/adapter/rack_spec.rb
|
@@ -172,7 +197,7 @@ licenses:
|
|
172
197
|
- MIT
|
173
198
|
metadata:
|
174
199
|
homepage_uri: https://lostisland.github.io/faraday
|
175
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.
|
200
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.4.0
|
176
201
|
source_code_uri: https://github.com/lostisland/faraday
|
177
202
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
178
203
|
post_install_message:
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Adapter
|
5
|
-
# Excon adapter.
|
6
|
-
class Excon < Faraday::Adapter
|
7
|
-
dependency 'excon'
|
8
|
-
|
9
|
-
def build_connection(env)
|
10
|
-
opts = opts_from_env(env)
|
11
|
-
::Excon.new(env[:url].to_s, opts.merge(@connection_options))
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
super
|
16
|
-
|
17
|
-
req_opts = {
|
18
|
-
method: env[:method].to_s.upcase,
|
19
|
-
headers: env[:request_headers],
|
20
|
-
body: read_body(env)
|
21
|
-
}
|
22
|
-
|
23
|
-
req = env[:request]
|
24
|
-
if req&.stream_response?
|
25
|
-
total = 0
|
26
|
-
req_opts[:response_block] = lambda do |chunk, _remain, _total|
|
27
|
-
req.on_data.call(chunk, total += chunk.size)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
resp = connection(env) { |http| http.request(req_opts) }
|
32
|
-
save_response(env, resp.status.to_i, resp.body, resp.headers,
|
33
|
-
resp.reason_phrase)
|
34
|
-
|
35
|
-
@app.call(env)
|
36
|
-
rescue ::Excon::Errors::SocketError => e
|
37
|
-
raise Faraday::TimeoutError, e if e.message.match?(/\btimeout\b/)
|
38
|
-
|
39
|
-
raise Faraday::SSLError, e if e.message.match?(/\bcertificate\b/)
|
40
|
-
|
41
|
-
raise Faraday::ConnectionFailed, e
|
42
|
-
rescue ::Excon::Errors::Timeout => e
|
43
|
-
raise Faraday::TimeoutError, e
|
44
|
-
end
|
45
|
-
|
46
|
-
# TODO: support streaming requests
|
47
|
-
def read_body(env)
|
48
|
-
env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def opts_from_env(env)
|
54
|
-
opts = {}
|
55
|
-
amend_opts_with_ssl!(opts, env[:ssl]) if needs_ssl_settings?(env)
|
56
|
-
|
57
|
-
if (req = env[:request])
|
58
|
-
amend_opts_with_timeouts!(opts, req)
|
59
|
-
amend_opts_with_proxy_settings!(opts, req)
|
60
|
-
end
|
61
|
-
|
62
|
-
opts
|
63
|
-
end
|
64
|
-
|
65
|
-
def needs_ssl_settings?(env)
|
66
|
-
env[:url].scheme == 'https' && env[:ssl]
|
67
|
-
end
|
68
|
-
|
69
|
-
OPTS_KEYS = [
|
70
|
-
%i[client_cert client_cert],
|
71
|
-
%i[client_key client_key],
|
72
|
-
%i[certificate certificate],
|
73
|
-
%i[private_key private_key],
|
74
|
-
%i[ssl_ca_path ca_path],
|
75
|
-
%i[ssl_ca_file ca_file],
|
76
|
-
%i[ssl_version version],
|
77
|
-
%i[ssl_min_version min_version],
|
78
|
-
%i[ssl_max_version max_version]
|
79
|
-
].freeze
|
80
|
-
|
81
|
-
def amend_opts_with_ssl!(opts, ssl)
|
82
|
-
opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
|
83
|
-
# https://github.com/geemus/excon/issues/106
|
84
|
-
# https://github.com/jruby/jruby-ossl/issues/19
|
85
|
-
opts[:nonblock] = false
|
86
|
-
|
87
|
-
OPTS_KEYS.each do |(key_in_opts, key_in_ssl)|
|
88
|
-
next unless ssl[key_in_ssl]
|
89
|
-
|
90
|
-
opts[key_in_opts] = ssl[key_in_ssl]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def amend_opts_with_timeouts!(opts, req)
|
95
|
-
if (sec = request_timeout(:read, req))
|
96
|
-
opts[:read_timeout] = sec
|
97
|
-
end
|
98
|
-
|
99
|
-
if (sec = request_timeout(:write, req))
|
100
|
-
opts[:write_timeout] = sec
|
101
|
-
end
|
102
|
-
|
103
|
-
return unless (sec = request_timeout(:open, req))
|
104
|
-
|
105
|
-
opts[:connect_timeout] = sec
|
106
|
-
end
|
107
|
-
|
108
|
-
def amend_opts_with_proxy_settings!(opts, req)
|
109
|
-
opts[:proxy] = proxy_settings_for_opts(req[:proxy]) if req[:proxy]
|
110
|
-
end
|
111
|
-
|
112
|
-
def proxy_settings_for_opts(proxy)
|
113
|
-
{
|
114
|
-
host: proxy[:uri].host,
|
115
|
-
hostname: proxy[:uri].hostname,
|
116
|
-
port: proxy[:uri].port,
|
117
|
-
scheme: proxy[:uri].scheme,
|
118
|
-
user: proxy[:user],
|
119
|
-
password: proxy[:password]
|
120
|
-
}
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -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, Net::OpenTimeout => 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
|