faraday 0.13.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +496 -0
- data/LICENSE.md +1 -1
- data/README.md +28 -328
- data/Rakefile +7 -0
- data/examples/client_spec.rb +97 -0
- data/examples/client_test.rb +118 -0
- data/lib/faraday/adapter/test.rb +127 -68
- data/lib/faraday/adapter.rb +71 -22
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/connection.rb +314 -226
- data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +176 -0
- data/lib/faraday/error.rb +121 -37
- data/lib/faraday/logging/formatter.rb +106 -0
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +18 -25
- data/lib/faraday/middleware_registry.rb +65 -0
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +181 -0
- data/lib/faraday/options/proxy_options.rb +32 -0
- data/lib/faraday/options/request_options.rb +22 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/options.rb +41 -195
- data/lib/faraday/parameters.rb +4 -196
- data/lib/faraday/rack_builder.rb +91 -74
- data/lib/faraday/request/authorization.rb +37 -29
- data/lib/faraday/request/instrumentation.rb +47 -27
- data/lib/faraday/request/json.rb +55 -0
- data/lib/faraday/request/url_encoded.rb +45 -23
- data/lib/faraday/request.rb +74 -32
- data/lib/faraday/response/json.rb +54 -0
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +57 -14
- data/lib/faraday/response.rb +26 -33
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/lib/faraday/utils.rb +47 -251
- data/lib/faraday/version.rb +5 -0
- data/lib/faraday.rb +104 -197
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/spec/faraday/adapter/test_spec.rb +377 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/connection_spec.rb +787 -0
- data/spec/faraday/error_spec.rb +60 -0
- data/spec/faraday/middleware_spec.rb +52 -0
- data/spec/faraday/options/env_spec.rb +70 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/spec/faraday/params_encoders/nested_spec.rb +142 -0
- data/spec/faraday/rack_builder_spec.rb +302 -0
- data/spec/faraday/request/authorization_spec.rb +83 -0
- data/spec/faraday/request/instrumentation_spec.rb +74 -0
- data/spec/faraday/request/json_spec.rb +111 -0
- data/spec/faraday/request/url_encoded_spec.rb +82 -0
- data/spec/faraday/request_spec.rb +109 -0
- data/spec/faraday/response/json_spec.rb +117 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/raise_error_spec.rb +172 -0
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +117 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +132 -0
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +96 -0
- data/spec/support/shared_examples/adapter.rb +104 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +249 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- metadata +71 -34
- data/lib/faraday/adapter/em_http.rb +0 -243
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
- data/lib/faraday/adapter/em_synchrony.rb +0 -106
- data/lib/faraday/adapter/excon.rb +0 -80
- data/lib/faraday/adapter/httpclient.rb +0 -128
- data/lib/faraday/adapter/net_http.rb +0 -135
- data/lib/faraday/adapter/net_http_persistent.rb +0 -54
- data/lib/faraday/adapter/patron.rb +0 -83
- data/lib/faraday/adapter/rack.rb +0 -58
- data/lib/faraday/adapter/typhoeus.rb +0 -123
- data/lib/faraday/autoload.rb +0 -84
- data/lib/faraday/request/basic_authentication.rb +0 -13
- data/lib/faraday/request/multipart.rb +0 -68
- data/lib/faraday/request/retry.rb +0 -164
- data/lib/faraday/request/token_authentication.rb +0 -15
- data/lib/faraday/upload_io.rb +0 -67
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module HelperMethods
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def features(*features)
|
11
|
+
@features = features
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_feature(name)
|
15
|
+
yield if block_given? && feature?(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def feature?(name)
|
19
|
+
if @features.nil?
|
20
|
+
superclass.feature?(name) if superclass.respond_to?(:feature?)
|
21
|
+
elsif @features.include?(name)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_with_body?(method)
|
27
|
+
METHODS_WITH_BODY.include?(method.to_s)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def ssl_mode?
|
32
|
+
ENV['SSL'] == 'yes'
|
33
|
+
end
|
34
|
+
|
35
|
+
def normalize(url)
|
36
|
+
Faraday::Utils::URI(url)
|
37
|
+
end
|
38
|
+
|
39
|
+
def with_default_uri_parser(parser)
|
40
|
+
old_parser = Faraday::Utils.default_uri_parser
|
41
|
+
begin
|
42
|
+
Faraday::Utils.default_uri_parser = parser
|
43
|
+
yield
|
44
|
+
ensure
|
45
|
+
Faraday::Utils.default_uri_parser = old_parser
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def with_env(new_env)
|
50
|
+
old_env = {}
|
51
|
+
|
52
|
+
new_env.each do |key, value|
|
53
|
+
old_env[key] = ENV.fetch(key, false)
|
54
|
+
ENV[key] = value
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
yield
|
59
|
+
ensure
|
60
|
+
old_env.each do |key, value|
|
61
|
+
value == false ? ENV.delete(key) : ENV[key] = value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def with_env_proxy_disabled
|
67
|
+
Faraday.ignore_env_proxy = true
|
68
|
+
|
69
|
+
begin
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
Faraday.ignore_env_proxy = false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def capture_warnings
|
77
|
+
old = $stderr
|
78
|
+
$stderr = StringIO.new
|
79
|
+
begin
|
80
|
+
yield
|
81
|
+
$stderr.string
|
82
|
+
ensure
|
83
|
+
$stderr = old
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def method_with_body?(method)
|
88
|
+
self.class.method_with_body?(method)
|
89
|
+
end
|
90
|
+
|
91
|
+
def big_string
|
92
|
+
kb = 1024
|
93
|
+
(32..126).map(&:chr).cycle.take(50 * kb).join
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'an adapter' do |**options|
|
4
|
+
before { skip } if options[:skip]
|
5
|
+
|
6
|
+
context 'with SSL enabled' do
|
7
|
+
before { ENV['SSL'] = 'yes' }
|
8
|
+
include_examples 'adapter examples', options
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'with SSL disabled' do
|
12
|
+
before { ENV['SSL'] = 'no' }
|
13
|
+
include_examples 'adapter examples', options
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples 'adapter examples' do |**options|
|
18
|
+
include Faraday::StreamingResponseChecker
|
19
|
+
|
20
|
+
let(:adapter) { described_class.name.split('::').last }
|
21
|
+
|
22
|
+
let(:conn_options) { { headers: { 'X-Faraday-Adapter' => adapter } }.merge(options[:conn_options] || {}) }
|
23
|
+
|
24
|
+
let(:adapter_options) do
|
25
|
+
return [] unless options[:adapter_options]
|
26
|
+
|
27
|
+
if options[:adapter_options].is_a?(Array)
|
28
|
+
options[:adapter_options]
|
29
|
+
else
|
30
|
+
[options[:adapter_options]]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:protocol) { ssl_mode? ? 'https' : 'http' }
|
35
|
+
let(:remote) { "#{protocol}://example.com" }
|
36
|
+
let(:stub_remote) { remote }
|
37
|
+
|
38
|
+
let(:conn) do
|
39
|
+
conn_options[:ssl] ||= {}
|
40
|
+
conn_options[:ssl][:ca_file] ||= ENV['SSL_FILE']
|
41
|
+
|
42
|
+
Faraday.new(remote, conn_options) do |conn|
|
43
|
+
conn.request :url_encoded
|
44
|
+
conn.response :raise_error
|
45
|
+
conn.adapter described_class, *adapter_options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
let!(:request_stub) { stub_request(http_method, stub_remote) }
|
50
|
+
|
51
|
+
after do
|
52
|
+
expect(request_stub).to have_been_requested unless request_stub.disabled?
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#delete' do
|
56
|
+
let(:http_method) { :delete }
|
57
|
+
|
58
|
+
it_behaves_like 'a request method', :delete
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#get' do
|
62
|
+
let(:http_method) { :get }
|
63
|
+
|
64
|
+
it_behaves_like 'a request method', :get
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#head' do
|
68
|
+
let(:http_method) { :head }
|
69
|
+
|
70
|
+
it_behaves_like 'a request method', :head
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#options' do
|
74
|
+
let(:http_method) { :options }
|
75
|
+
|
76
|
+
it_behaves_like 'a request method', :options
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#patch' do
|
80
|
+
let(:http_method) { :patch }
|
81
|
+
|
82
|
+
it_behaves_like 'a request method', :patch
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#post' do
|
86
|
+
let(:http_method) { :post }
|
87
|
+
|
88
|
+
it_behaves_like 'a request method', :post
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#put' do
|
92
|
+
let(:http_method) { :put }
|
93
|
+
|
94
|
+
it_behaves_like 'a request method', :put
|
95
|
+
end
|
96
|
+
|
97
|
+
on_feature :trace_method do
|
98
|
+
describe '#trace' do
|
99
|
+
let(:http_method) { :trace }
|
100
|
+
|
101
|
+
it_behaves_like 'a request method', :trace
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'a params encoder' do
|
4
|
+
it 'escapes safe buffer' do
|
5
|
+
monies = FakeSafeBuffer.new('$32,000.00')
|
6
|
+
expect(subject.encode('a' => monies)).to eq('a=%2432%2C000.00')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'raises type error for empty string' do
|
10
|
+
expect { subject.encode('') }.to raise_error(TypeError) do |error|
|
11
|
+
expect(error.message).to eq("Can't convert String into Hash.")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'encodes nil' do
|
16
|
+
expect(subject.encode('a' => nil)).to eq('a')
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'proxy examples' do
|
4
|
+
it 'handles requests with proxy' do
|
5
|
+
res = conn.public_send(http_method, '/')
|
6
|
+
|
7
|
+
expect(res.status).to eq(200)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'handles proxy failures' do
|
11
|
+
request_stub.to_return(status: 407)
|
12
|
+
|
13
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(Faraday::ProxyAuthError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
shared_examples 'a request method' do |http_method|
|
18
|
+
let(:query_or_body) { method_with_body?(http_method) ? :body : :query }
|
19
|
+
let(:response) { conn.public_send(http_method, '/') }
|
20
|
+
|
21
|
+
unless http_method == :head && feature?(:skip_response_body_on_head)
|
22
|
+
it 'retrieves the response body' do
|
23
|
+
res_body = 'test'
|
24
|
+
request_stub.to_return(body: res_body)
|
25
|
+
expect(conn.public_send(http_method, '/').body).to eq(res_body)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'handles headers with multiple values' do
|
30
|
+
request_stub.to_return(headers: { 'Set-Cookie' => 'name=value' })
|
31
|
+
expect(response.headers['set-cookie']).to eq('name=value')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'retrieves the response headers' do
|
35
|
+
request_stub.to_return(headers: { 'Content-Type' => 'text/plain' })
|
36
|
+
expect(response.headers['Content-Type']).to match(%r{text/plain})
|
37
|
+
expect(response.headers['content-type']).to match(%r{text/plain})
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'sends user agent' do
|
41
|
+
request_stub.with(headers: { 'User-Agent' => 'Agent Faraday' })
|
42
|
+
conn.public_send(http_method, '/', nil, user_agent: 'Agent Faraday')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'represents empty body response as blank string' do
|
46
|
+
expect(response.body).to eq('')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'handles connection error' do
|
50
|
+
request_stub.disable
|
51
|
+
expect { conn.public_send(http_method, 'http://localhost:4') }.to raise_error(Faraday::ConnectionFailed)
|
52
|
+
end
|
53
|
+
|
54
|
+
on_feature :local_socket_binding do
|
55
|
+
it 'binds local socket' do
|
56
|
+
stub_request(http_method, 'http://example.com')
|
57
|
+
|
58
|
+
host = '1.2.3.4'
|
59
|
+
port = 1234
|
60
|
+
conn_options[:request] = { bind: { host: host, port: port } }
|
61
|
+
|
62
|
+
conn.public_send(http_method, '/')
|
63
|
+
|
64
|
+
expect(conn.options[:bind][:host]).to eq(host)
|
65
|
+
expect(conn.options[:bind][:port]).to eq(port)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# context 'when wrong ssl certificate is provided' do
|
70
|
+
# let(:ca_file_path) { 'tmp/faraday-different-ca-cert.crt' }
|
71
|
+
# before { conn_options.merge!(ssl: { ca_file: ca_file_path }) }
|
72
|
+
#
|
73
|
+
# it do
|
74
|
+
# expect { conn.public_send(http_method, '/') }.to raise_error(Faraday::SSLError) # do |ex|
|
75
|
+
# expect(ex.message).to include?('certificate')
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
|
80
|
+
on_feature :request_body_on_query_methods do
|
81
|
+
it 'sends request body' do
|
82
|
+
request_stub.with({ body: 'test' })
|
83
|
+
res = if query_or_body == :body
|
84
|
+
conn.public_send(http_method, '/', 'test')
|
85
|
+
else
|
86
|
+
conn.public_send(http_method, '/') do |req|
|
87
|
+
req.body = 'test'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
expect(res.env.request_body).to eq('test')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'sends url encoded parameters' do
|
95
|
+
payload = { name: 'zack' }
|
96
|
+
request_stub.with({ query_or_body => payload })
|
97
|
+
res = conn.public_send(http_method, '/', payload)
|
98
|
+
if query_or_body == :query
|
99
|
+
expect(res.env.request_body).to be_nil
|
100
|
+
else
|
101
|
+
expect(res.env.request_body).to eq('name=zack')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'sends url encoded nested parameters' do
|
106
|
+
payload = { name: { first: 'zack' } }
|
107
|
+
request_stub.with({ query_or_body => payload })
|
108
|
+
conn.public_send(http_method, '/', payload)
|
109
|
+
end
|
110
|
+
|
111
|
+
# TODO: This needs reimplementation: see https://github.com/lostisland/faraday/issues/718
|
112
|
+
# Should raise Faraday::TimeoutError
|
113
|
+
it 'supports timeout option' do
|
114
|
+
conn_options[:request] = { timeout: 1 }
|
115
|
+
request_stub.to_timeout
|
116
|
+
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
|
117
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
118
|
+
end
|
119
|
+
|
120
|
+
# TODO: This needs reimplementation: see https://github.com/lostisland/faraday/issues/718
|
121
|
+
# Should raise Faraday::ConnectionFailed
|
122
|
+
it 'supports open_timeout option' do
|
123
|
+
conn_options[:request] = { open_timeout: 1 }
|
124
|
+
request_stub.to_timeout
|
125
|
+
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
|
126
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
127
|
+
end
|
128
|
+
|
129
|
+
on_feature :reason_phrase_parse do
|
130
|
+
it 'parses the reason phrase' do
|
131
|
+
request_stub.to_return(status: [200, 'OK'])
|
132
|
+
expect(response.reason_phrase).to eq('OK')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
on_feature :compression do
|
137
|
+
# Accept-Encoding header not sent for HEAD requests as body is not expected in the response.
|
138
|
+
unless http_method == :head
|
139
|
+
it 'handles gzip compression' do
|
140
|
+
request_stub.with(headers: { 'Accept-Encoding' => /\bgzip\b/ })
|
141
|
+
conn.public_send(http_method, '/')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'handles deflate compression' do
|
145
|
+
request_stub.with(headers: { 'Accept-Encoding' => /\bdeflate\b/ })
|
146
|
+
conn.public_send(http_method, '/')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
on_feature :streaming do
|
152
|
+
describe 'streaming' do
|
153
|
+
let(:streamed) { [] }
|
154
|
+
|
155
|
+
context 'when response is empty' do
|
156
|
+
it do
|
157
|
+
conn.public_send(http_method, '/') do |req|
|
158
|
+
req.options.on_data = proc { |*args| streamed << args }
|
159
|
+
end
|
160
|
+
|
161
|
+
expect(streamed).to eq([['', 0]])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'when response contains big data' do
|
166
|
+
before { request_stub.to_return(body: big_string) }
|
167
|
+
|
168
|
+
it 'handles streaming' do
|
169
|
+
response = conn.public_send(http_method, '/') do |req|
|
170
|
+
req.options.on_data = proc { |*args| streamed << args }
|
171
|
+
end
|
172
|
+
|
173
|
+
expect(response.body).to eq('')
|
174
|
+
check_streaming_response(streamed, chunk_size: 16 * 1024)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
on_feature :parallel do
|
181
|
+
context 'with parallel setup' do
|
182
|
+
before do
|
183
|
+
@resp1 = nil
|
184
|
+
@resp2 = nil
|
185
|
+
@payload1 = { a: '1' }
|
186
|
+
@payload2 = { b: '2' }
|
187
|
+
|
188
|
+
request_stub
|
189
|
+
.with({ query_or_body => @payload1 })
|
190
|
+
.to_return(body: @payload1.to_json)
|
191
|
+
|
192
|
+
stub_request(http_method, remote)
|
193
|
+
.with({ query_or_body => @payload2 })
|
194
|
+
.to_return(body: @payload2.to_json)
|
195
|
+
|
196
|
+
conn.in_parallel do
|
197
|
+
@resp1 = conn.public_send(http_method, '/', @payload1)
|
198
|
+
@resp2 = conn.public_send(http_method, '/', @payload2)
|
199
|
+
|
200
|
+
expect(conn.in_parallel?).to be_truthy
|
201
|
+
expect(@resp1.body).to be_nil
|
202
|
+
expect(@resp2.body).to be_nil
|
203
|
+
end
|
204
|
+
|
205
|
+
expect(conn.in_parallel?).to be_falsey
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'handles parallel requests status' do
|
209
|
+
expect(@resp1&.status).to eq(200)
|
210
|
+
expect(@resp2&.status).to eq(200)
|
211
|
+
end
|
212
|
+
|
213
|
+
unless http_method == :head && feature?(:skip_response_body_on_head)
|
214
|
+
it 'handles parallel requests body' do
|
215
|
+
expect(@resp1&.body).to eq(@payload1.to_json)
|
216
|
+
expect(@resp2&.body).to eq(@payload2.to_json)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when a proxy is provided as option' do
|
223
|
+
before do
|
224
|
+
conn_options[:proxy] = 'http://env-proxy.com:80'
|
225
|
+
end
|
226
|
+
|
227
|
+
include_examples 'proxy examples'
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when http_proxy env variable is set' do
|
231
|
+
let(:proxy_url) { 'http://env-proxy.com:80' }
|
232
|
+
|
233
|
+
around do |example|
|
234
|
+
with_env 'http_proxy' => proxy_url do
|
235
|
+
example.run
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
include_examples 'proxy examples'
|
240
|
+
|
241
|
+
context 'when the env proxy is ignored' do
|
242
|
+
around do |example|
|
243
|
+
with_env_proxy_disabled(&example)
|
244
|
+
end
|
245
|
+
|
246
|
+
include_examples 'proxy examples'
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module StreamingResponseChecker
|
5
|
+
def check_streaming_response(streamed, options = {})
|
6
|
+
opts = {
|
7
|
+
prefix: '',
|
8
|
+
streaming?: true
|
9
|
+
}.merge(options)
|
10
|
+
|
11
|
+
expected_response = opts[:prefix] + big_string
|
12
|
+
|
13
|
+
chunks, sizes = streamed.transpose
|
14
|
+
|
15
|
+
# Check that the total size of the chunks (via the last size returned)
|
16
|
+
# is the same size as the expected_response
|
17
|
+
expect(sizes.last).to eq(expected_response.bytesize)
|
18
|
+
|
19
|
+
start_index = 0
|
20
|
+
expected_chunks = []
|
21
|
+
chunks.each do |actual_chunk|
|
22
|
+
expected_chunk = expected_response[start_index..((start_index + actual_chunk.bytesize) - 1)]
|
23
|
+
expected_chunks << expected_chunk
|
24
|
+
start_index += expected_chunk.bytesize
|
25
|
+
end
|
26
|
+
|
27
|
+
# it's easier to read a smaller portion, so we check that first
|
28
|
+
expect(expected_chunks[0][0..255]).to eq(chunks[0][0..255])
|
29
|
+
|
30
|
+
[expected_chunks, chunks].transpose.each do |expected, actual|
|
31
|
+
expect(actual).to eq(expected)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,98 +1,135 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- "@technoweenie"
|
8
|
+
- "@iMacTia"
|
9
|
+
- "@olleolleolle"
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2022-01-04 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
16
|
+
name: ruby2_keywords
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
19
|
- - ">="
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '3'
|
21
|
+
version: 0.0.4
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3'
|
28
|
+
version: 0.0.4
|
33
29
|
description:
|
34
30
|
email: technoweenie@gmail.com
|
35
31
|
executables: []
|
36
32
|
extensions: []
|
37
33
|
extra_rdoc_files: []
|
38
34
|
files:
|
35
|
+
- CHANGELOG.md
|
39
36
|
- LICENSE.md
|
40
37
|
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- examples/client_spec.rb
|
40
|
+
- examples/client_test.rb
|
41
41
|
- lib/faraday.rb
|
42
42
|
- lib/faraday/adapter.rb
|
43
|
-
- lib/faraday/adapter/em_http.rb
|
44
|
-
- lib/faraday/adapter/em_http_ssl_patch.rb
|
45
|
-
- lib/faraday/adapter/em_synchrony.rb
|
46
|
-
- lib/faraday/adapter/em_synchrony/parallel_manager.rb
|
47
|
-
- lib/faraday/adapter/excon.rb
|
48
|
-
- lib/faraday/adapter/httpclient.rb
|
49
|
-
- lib/faraday/adapter/net_http.rb
|
50
|
-
- lib/faraday/adapter/net_http_persistent.rb
|
51
|
-
- lib/faraday/adapter/patron.rb
|
52
|
-
- lib/faraday/adapter/rack.rb
|
53
43
|
- lib/faraday/adapter/test.rb
|
54
|
-
- lib/faraday/
|
55
|
-
- lib/faraday/autoload.rb
|
44
|
+
- lib/faraday/adapter_registry.rb
|
56
45
|
- lib/faraday/connection.rb
|
46
|
+
- lib/faraday/encoders/flat_params_encoder.rb
|
47
|
+
- lib/faraday/encoders/nested_params_encoder.rb
|
57
48
|
- lib/faraday/error.rb
|
49
|
+
- lib/faraday/logging/formatter.rb
|
50
|
+
- lib/faraday/methods.rb
|
58
51
|
- lib/faraday/middleware.rb
|
52
|
+
- lib/faraday/middleware_registry.rb
|
59
53
|
- lib/faraday/options.rb
|
54
|
+
- lib/faraday/options/connection_options.rb
|
55
|
+
- lib/faraday/options/env.rb
|
56
|
+
- lib/faraday/options/proxy_options.rb
|
57
|
+
- lib/faraday/options/request_options.rb
|
58
|
+
- lib/faraday/options/ssl_options.rb
|
60
59
|
- lib/faraday/parameters.rb
|
61
60
|
- lib/faraday/rack_builder.rb
|
62
61
|
- lib/faraday/request.rb
|
63
62
|
- lib/faraday/request/authorization.rb
|
64
|
-
- lib/faraday/request/basic_authentication.rb
|
65
63
|
- lib/faraday/request/instrumentation.rb
|
66
|
-
- lib/faraday/request/
|
67
|
-
- lib/faraday/request/retry.rb
|
68
|
-
- lib/faraday/request/token_authentication.rb
|
64
|
+
- lib/faraday/request/json.rb
|
69
65
|
- lib/faraday/request/url_encoded.rb
|
70
66
|
- lib/faraday/response.rb
|
67
|
+
- lib/faraday/response/json.rb
|
71
68
|
- lib/faraday/response/logger.rb
|
72
69
|
- lib/faraday/response/raise_error.rb
|
73
|
-
- lib/faraday/upload_io.rb
|
74
70
|
- lib/faraday/utils.rb
|
75
|
-
|
71
|
+
- lib/faraday/utils/headers.rb
|
72
|
+
- lib/faraday/utils/params_hash.rb
|
73
|
+
- lib/faraday/version.rb
|
74
|
+
- spec/external_adapters/faraday_specs_setup.rb
|
75
|
+
- spec/faraday/adapter/test_spec.rb
|
76
|
+
- spec/faraday/adapter_registry_spec.rb
|
77
|
+
- spec/faraday/adapter_spec.rb
|
78
|
+
- spec/faraday/connection_spec.rb
|
79
|
+
- spec/faraday/error_spec.rb
|
80
|
+
- spec/faraday/middleware_spec.rb
|
81
|
+
- spec/faraday/options/env_spec.rb
|
82
|
+
- spec/faraday/options/options_spec.rb
|
83
|
+
- spec/faraday/options/proxy_options_spec.rb
|
84
|
+
- spec/faraday/options/request_options_spec.rb
|
85
|
+
- spec/faraday/params_encoders/flat_spec.rb
|
86
|
+
- spec/faraday/params_encoders/nested_spec.rb
|
87
|
+
- spec/faraday/rack_builder_spec.rb
|
88
|
+
- spec/faraday/request/authorization_spec.rb
|
89
|
+
- spec/faraday/request/instrumentation_spec.rb
|
90
|
+
- spec/faraday/request/json_spec.rb
|
91
|
+
- spec/faraday/request/url_encoded_spec.rb
|
92
|
+
- spec/faraday/request_spec.rb
|
93
|
+
- spec/faraday/response/json_spec.rb
|
94
|
+
- spec/faraday/response/logger_spec.rb
|
95
|
+
- spec/faraday/response/raise_error_spec.rb
|
96
|
+
- spec/faraday/response_spec.rb
|
97
|
+
- spec/faraday/utils/headers_spec.rb
|
98
|
+
- spec/faraday/utils_spec.rb
|
99
|
+
- spec/faraday_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
- spec/support/disabling_stub.rb
|
102
|
+
- spec/support/fake_safe_buffer.rb
|
103
|
+
- spec/support/helper_methods.rb
|
104
|
+
- spec/support/shared_examples/adapter.rb
|
105
|
+
- spec/support/shared_examples/params_encoder.rb
|
106
|
+
- spec/support/shared_examples/request_method.rb
|
107
|
+
- spec/support/streaming_response_checker.rb
|
108
|
+
homepage: https://lostisland.github.io/faraday
|
76
109
|
licenses:
|
77
110
|
- MIT
|
78
|
-
metadata:
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://lostisland.github.io/faraday
|
113
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.0.0
|
114
|
+
source_code_uri: https://github.com/lostisland/faraday
|
115
|
+
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
79
116
|
post_install_message:
|
80
117
|
rdoc_options: []
|
81
118
|
require_paths:
|
82
119
|
- lib
|
120
|
+
- spec/external_adapters
|
83
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
122
|
requirements:
|
85
123
|
- - ">="
|
86
124
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
125
|
+
version: '2.6'
|
88
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
127
|
requirements:
|
90
128
|
- - ">="
|
91
129
|
- !ruby/object:Gem::Version
|
92
130
|
version: '0'
|
93
131
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.4.5
|
132
|
+
rubygems_version: 3.1.6
|
96
133
|
signing_key:
|
97
134
|
specification_version: 4
|
98
135
|
summary: HTTP/REST API client library.
|