faraday 0.17.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -8
- data/LICENSE.md +1 -1
- data/README.md +17 -358
- data/Rakefile +1 -7
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday/adapter/em_http.rb +143 -100
- data/lib/faraday/adapter/em_http_ssl_patch.rb +24 -18
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
- data/lib/faraday/adapter/em_synchrony.rb +104 -60
- data/lib/faraday/adapter/excon.rb +98 -56
- data/lib/faraday/adapter/httpclient.rb +83 -59
- data/lib/faraday/adapter/net_http.rb +129 -63
- data/lib/faraday/adapter/net_http_persistent.rb +50 -27
- data/lib/faraday/adapter/patron.rb +80 -43
- data/lib/faraday/adapter/rack.rb +30 -13
- data/lib/faraday/adapter/test.rb +86 -53
- data/lib/faraday/adapter/typhoeus.rb +4 -1
- data/lib/faraday/adapter.rb +83 -22
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/autoload.rb +47 -36
- data/lib/faraday/connection.rb +312 -182
- data/lib/faraday/dependency_loader.rb +39 -0
- 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 +17 -35
- data/lib/faraday/file_part.rb +128 -0
- data/lib/faraday/logging/formatter.rb +105 -0
- data/lib/faraday/middleware.rb +12 -28
- data/lib/faraday/middleware_registry.rb +129 -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 +28 -0
- data/lib/faraday/options/request_options.rb +22 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/options.rb +36 -191
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/parameters.rb +4 -197
- data/lib/faraday/rack_builder.rb +76 -64
- data/lib/faraday/request/authorization.rb +44 -30
- data/lib/faraday/request/basic_authentication.rb +14 -7
- data/lib/faraday/request/instrumentation.rb +45 -27
- data/lib/faraday/request/multipart.rb +86 -48
- data/lib/faraday/request/retry.rb +197 -171
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +43 -23
- data/lib/faraday/request.rb +86 -46
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +49 -18
- data/lib/faraday/response.rb +24 -14
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/lib/faraday/utils.rb +38 -247
- data/lib/faraday.rb +94 -175
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/spec/faraday/adapter/em_http_spec.rb +47 -0
- data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
- data/spec/faraday/adapter/excon_spec.rb +49 -0
- data/spec/faraday/adapter/httpclient_spec.rb +73 -0
- data/spec/faraday/adapter/net_http_persistent_spec.rb +57 -0
- data/spec/faraday/adapter/net_http_spec.rb +64 -0
- data/spec/faraday/adapter/patron_spec.rb +18 -0
- data/spec/faraday/adapter/rack_spec.rb +8 -0
- data/spec/faraday/adapter/test_spec.rb +260 -0
- data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/composite_read_io_spec.rb +80 -0
- data/spec/faraday/connection_spec.rb +691 -0
- data/spec/faraday/error_spec.rb +0 -57
- data/spec/faraday/middleware_spec.rb +26 -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 +37 -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 +345 -0
- data/spec/faraday/request/authorization_spec.rb +88 -0
- data/spec/faraday/request/instrumentation_spec.rb +76 -0
- data/spec/faraday/request/multipart_spec.rb +302 -0
- data/spec/faraday/request/retry_spec.rb +242 -0
- data/spec/faraday/request/url_encoded_spec.rb +83 -0
- data/spec/faraday/request_spec.rb +120 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/middleware_spec.rb +68 -0
- data/spec/faraday/response/raise_error_spec.rb +48 -15
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +56 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +63 -36
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +133 -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 +234 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +81 -38
- data/lib/faraday/deprecate.rb +0 -109
- data/lib/faraday/upload_io.rb +0 -67
- data/spec/faraday/deprecate_spec.rb +0 -147
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -30
- data/test/adapters/em_synchrony_test.rb +0 -32
- data/test/adapters/excon_test.rb +0 -30
- data/test/adapters/httpclient_test.rb +0 -34
- data/test/adapters/integration.rb +0 -263
- data/test/adapters/logger_test.rb +0 -136
- data/test/adapters/net_http_persistent_test.rb +0 -114
- data/test/adapters/net_http_test.rb +0 -79
- data/test/adapters/patron_test.rb +0 -40
- data/test/adapters/rack_test.rb +0 -38
- data/test/adapters/test_middleware_test.rb +0 -157
- data/test/adapters/typhoeus_test.rb +0 -38
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -109
- data/test/connection_test.rb +0 -738
- data/test/env_test.rb +0 -268
- data/test/helper.rb +0 -75
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -282
- data/test/middleware_stack_test.rb +0 -260
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -333
- data/test/parameters_test.rb +0 -157
- data/test/request_middleware_test.rb +0 -126
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -98
@@ -0,0 +1,234 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'a request method' do |http_method|
|
4
|
+
let(:query_or_body) { method_with_body?(http_method) ? :body : :query }
|
5
|
+
let(:response) { conn.public_send(http_method, '/') }
|
6
|
+
|
7
|
+
unless http_method == :head && feature?(:skip_response_body_on_head)
|
8
|
+
it 'retrieves the response body' do
|
9
|
+
res_body = 'test'
|
10
|
+
request_stub.to_return(body: res_body)
|
11
|
+
expect(conn.public_send(http_method, '/').body).to eq(res_body)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'handles headers with multiple values' do
|
16
|
+
request_stub.to_return(headers: { 'Set-Cookie' => 'name=value' })
|
17
|
+
expect(response.headers['set-cookie']).to eq('name=value')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'retrieves the response headers' do
|
21
|
+
request_stub.to_return(headers: { 'Content-Type' => 'text/plain' })
|
22
|
+
expect(response.headers['Content-Type']).to match(%r{text/plain})
|
23
|
+
expect(response.headers['content-type']).to match(%r{text/plain})
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'sends user agent' do
|
27
|
+
request_stub.with(headers: { 'User-Agent' => 'Agent Faraday' })
|
28
|
+
conn.public_send(http_method, '/', nil, user_agent: 'Agent Faraday')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'represents empty body response as blank string' do
|
32
|
+
expect(response.body).to eq('')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'handles connection error' do
|
36
|
+
request_stub.disable
|
37
|
+
expect { conn.public_send(http_method, 'http://localhost:4') }.to raise_error(Faraday::ConnectionFailed)
|
38
|
+
end
|
39
|
+
|
40
|
+
on_feature :local_socket_binding do
|
41
|
+
it 'binds local socket' do
|
42
|
+
stub_request(http_method, 'http://example.com')
|
43
|
+
|
44
|
+
host = '1.2.3.4'
|
45
|
+
port = 1234
|
46
|
+
conn_options[:request] = { bind: { host: host, port: port } }
|
47
|
+
|
48
|
+
conn.public_send(http_method, '/')
|
49
|
+
|
50
|
+
expect(conn.options[:bind][:host]).to eq(host)
|
51
|
+
expect(conn.options[:bind][:port]).to eq(port)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# context 'when wrong ssl certificate is provided' do
|
56
|
+
# let(:ca_file_path) { 'tmp/faraday-different-ca-cert.crt' }
|
57
|
+
# before { conn_options.merge!(ssl: { ca_file: ca_file_path }) }
|
58
|
+
#
|
59
|
+
# it do
|
60
|
+
# expect { conn.public_send(http_method, '/') }.to raise_error(Faraday::SSLError) # do |ex|
|
61
|
+
# expect(ex.message).to include?('certificate')
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
|
66
|
+
on_feature :request_body_on_query_methods do
|
67
|
+
it 'sends request body' do
|
68
|
+
request_stub.with(Hash[:body, 'test'])
|
69
|
+
res = if query_or_body == :body
|
70
|
+
conn.public_send(http_method, '/', 'test')
|
71
|
+
else
|
72
|
+
conn.public_send(http_method, '/') do |req|
|
73
|
+
req.body = 'test'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
expect(res.env.request_body).to eq('test')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'sends url encoded parameters' do
|
81
|
+
payload = { name: 'zack' }
|
82
|
+
request_stub.with(Hash[query_or_body, payload])
|
83
|
+
res = conn.public_send(http_method, '/', payload)
|
84
|
+
if query_or_body == :query
|
85
|
+
expect(res.env.request_body).to be_nil
|
86
|
+
else
|
87
|
+
expect(res.env.request_body).to eq('name=zack')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'sends url encoded nested parameters' do
|
92
|
+
payload = { name: { first: 'zack' } }
|
93
|
+
request_stub.with(Hash[query_or_body, payload])
|
94
|
+
conn.public_send(http_method, '/', payload)
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO: This needs reimplementation: see https://github.com/lostisland/faraday/issues/718
|
98
|
+
# Should raise Faraday::TimeoutError
|
99
|
+
it 'supports timeout option' do
|
100
|
+
conn_options[:request] = { timeout: 1 }
|
101
|
+
request_stub.to_timeout
|
102
|
+
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
|
103
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
104
|
+
end
|
105
|
+
|
106
|
+
# TODO: This needs reimplementation: see https://github.com/lostisland/faraday/issues/718
|
107
|
+
# Should raise Faraday::ConnectionFailed
|
108
|
+
it 'supports open_timeout option' do
|
109
|
+
conn_options[:request] = { open_timeout: 1 }
|
110
|
+
request_stub.to_timeout
|
111
|
+
exc = adapter == 'NetHttp' ? Faraday::ConnectionFailed : Faraday::TimeoutError
|
112
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Can't send files on get, head and delete methods
|
116
|
+
if method_with_body?(http_method)
|
117
|
+
it 'sends files' do
|
118
|
+
payload = { uploaded_file: multipart_file }
|
119
|
+
request_stub.with(headers: { 'Content-Type' => %r{\Amultipart/form-data} }) do |request|
|
120
|
+
# WebMock does not support matching body for multipart/form-data requests yet :(
|
121
|
+
# https://github.com/bblimke/webmock/issues/623
|
122
|
+
request.body.include?('RubyMultipartPost')
|
123
|
+
end
|
124
|
+
conn.public_send(http_method, '/', payload)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
on_feature :reason_phrase_parse do
|
129
|
+
it 'parses the reason phrase' do
|
130
|
+
request_stub.to_return(status: [200, 'OK'])
|
131
|
+
expect(response.reason_phrase).to eq('OK')
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
on_feature :compression do
|
136
|
+
# Accept-Encoding header not sent for HEAD requests as body is not expected in the response.
|
137
|
+
unless http_method == :head
|
138
|
+
it 'handles gzip compression' do
|
139
|
+
request_stub.with(headers: { 'Accept-Encoding' => /\bgzip\b/ })
|
140
|
+
conn.public_send(http_method, '/')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'handles deflate compression' do
|
144
|
+
request_stub.with(headers: { 'Accept-Encoding' => /\bdeflate\b/ })
|
145
|
+
conn.public_send(http_method, '/')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
on_feature :streaming do
|
151
|
+
describe 'streaming' do
|
152
|
+
let(:streamed) { [] }
|
153
|
+
|
154
|
+
context 'when response is empty' do
|
155
|
+
it do
|
156
|
+
conn.public_send(http_method, '/') do |req|
|
157
|
+
req.options.on_data = proc { |*args| streamed << args }
|
158
|
+
end
|
159
|
+
|
160
|
+
expect(streamed).to eq([['', 0]])
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when response contains big data' do
|
165
|
+
before { request_stub.to_return(body: big_string) }
|
166
|
+
|
167
|
+
it 'handles streaming' do
|
168
|
+
response = conn.public_send(http_method, '/') do |req|
|
169
|
+
req.options.on_data = proc { |*args| streamed << args }
|
170
|
+
end
|
171
|
+
|
172
|
+
expect(response.body).to eq('')
|
173
|
+
check_streaming_response(streamed, chunk_size: 16 * 1024)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
on_feature :parallel do
|
180
|
+
context 'with parallel setup' do
|
181
|
+
before do
|
182
|
+
@resp1 = nil
|
183
|
+
@resp2 = nil
|
184
|
+
@payload1 = { a: '1' }
|
185
|
+
@payload2 = { b: '2' }
|
186
|
+
|
187
|
+
request_stub
|
188
|
+
.with(Hash[query_or_body, @payload1])
|
189
|
+
.to_return(body: @payload1.to_json)
|
190
|
+
|
191
|
+
stub_request(http_method, remote)
|
192
|
+
.with(Hash[query_or_body, @payload2])
|
193
|
+
.to_return(body: @payload2.to_json)
|
194
|
+
|
195
|
+
conn.in_parallel do
|
196
|
+
@resp1 = conn.public_send(http_method, '/', @payload1)
|
197
|
+
@resp2 = conn.public_send(http_method, '/', @payload2)
|
198
|
+
|
199
|
+
expect(conn.in_parallel?).to be_truthy
|
200
|
+
expect(@resp1.body).to be_nil
|
201
|
+
expect(@resp2.body).to be_nil
|
202
|
+
end
|
203
|
+
|
204
|
+
expect(conn.in_parallel?).to be_falsey
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'handles parallel requests status' do
|
208
|
+
expect(@resp1&.status).to eq(200)
|
209
|
+
expect(@resp2&.status).to eq(200)
|
210
|
+
end
|
211
|
+
|
212
|
+
unless http_method == :head && feature?(:skip_response_body_on_head)
|
213
|
+
it 'handles parallel requests body' do
|
214
|
+
expect(@resp1&.body).to eq(@payload1.to_json)
|
215
|
+
expect(@resp2&.body).to eq(@payload2.to_json)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'handles requests with proxy' do
|
222
|
+
conn_options[:proxy] = 'http://google.co.uk'
|
223
|
+
|
224
|
+
res = conn.public_send(http_method, '/')
|
225
|
+
expect(res.status).to eq(200)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'handles proxy failures' do
|
229
|
+
conn_options[:proxy] = 'http://google.co.uk'
|
230
|
+
request_stub.to_return(status: 407)
|
231
|
+
|
232
|
+
expect { conn.public_send(http_method, '/') }.to raise_error(Faraday::ProxyAuthError)
|
233
|
+
end
|
234
|
+
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
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rack app used to test the Rack adapter.
|
4
|
+
# Uses Webmock to check if requests are registered, in which case it returns
|
5
|
+
# the registered response.
|
6
|
+
class WebmockRackApp
|
7
|
+
def call(env)
|
8
|
+
req_signature = WebMock::RequestSignature.new(
|
9
|
+
req_method(env),
|
10
|
+
req_uri(env),
|
11
|
+
body: req_body(env),
|
12
|
+
headers: req_headers(env)
|
13
|
+
)
|
14
|
+
|
15
|
+
WebMock::RequestRegistry
|
16
|
+
.instance
|
17
|
+
.requested_signatures
|
18
|
+
.put(req_signature)
|
19
|
+
|
20
|
+
process_response(req_signature)
|
21
|
+
end
|
22
|
+
|
23
|
+
def req_method(env)
|
24
|
+
env['REQUEST_METHOD'].downcase.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def req_uri(env)
|
28
|
+
scheme = env['rack.url_scheme']
|
29
|
+
host = env['SERVER_NAME']
|
30
|
+
port = env['SERVER_PORT']
|
31
|
+
path = env['PATH_INFO']
|
32
|
+
query = env['QUERY_STRING']
|
33
|
+
|
34
|
+
url = +"#{scheme}://#{host}:#{port}#{path}"
|
35
|
+
url += "?#{query}" if query
|
36
|
+
|
37
|
+
uri = WebMock::Util::URI.heuristic_parse(url)
|
38
|
+
uri.path = uri.normalized_path.gsub('[^:]//', '/')
|
39
|
+
uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def req_headers(env)
|
43
|
+
http_headers = env.select { |k, _| k.start_with?('HTTP_') }
|
44
|
+
.map { |k, v| [k[5..-1], v] }
|
45
|
+
.to_h
|
46
|
+
|
47
|
+
special_headers = Faraday::Adapter::Rack::SPECIAL_HEADERS
|
48
|
+
http_headers.merge(env.select { |k, _| special_headers.include?(k) })
|
49
|
+
end
|
50
|
+
|
51
|
+
def req_body(env)
|
52
|
+
env['rack.input'].read
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_response(req_signature)
|
56
|
+
res = WebMock::StubRegistry.instance.response_for_request(req_signature)
|
57
|
+
|
58
|
+
if res.nil? && req_signature.uri.host == 'localhost'
|
59
|
+
raise Faraday::ConnectionFailed, 'Trying to connect to localhost'
|
60
|
+
end
|
61
|
+
|
62
|
+
raise WebMock::NetConnectNotAllowedError, req_signature unless res
|
63
|
+
|
64
|
+
raise Faraday::TimeoutError if res.should_timeout
|
65
|
+
|
66
|
+
[res.status[0], res.headers || {}, [res.body || '']]
|
67
|
+
end
|
68
|
+
end
|
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-10-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multipart-post
|
@@ -32,6 +32,20 @@ dependencies:
|
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '3'
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: ruby2_keywords
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
35
49
|
description:
|
36
50
|
email: technoweenie@gmail.com
|
37
51
|
executables: []
|
@@ -42,6 +56,8 @@ files:
|
|
42
56
|
- LICENSE.md
|
43
57
|
- README.md
|
44
58
|
- Rakefile
|
59
|
+
- examples/client_spec.rb
|
60
|
+
- examples/client_test.rb
|
45
61
|
- lib/faraday.rb
|
46
62
|
- lib/faraday/adapter.rb
|
47
63
|
- lib/faraday/adapter/em_http.rb
|
@@ -56,12 +72,24 @@ files:
|
|
56
72
|
- lib/faraday/adapter/rack.rb
|
57
73
|
- lib/faraday/adapter/test.rb
|
58
74
|
- lib/faraday/adapter/typhoeus.rb
|
75
|
+
- lib/faraday/adapter_registry.rb
|
59
76
|
- lib/faraday/autoload.rb
|
60
77
|
- lib/faraday/connection.rb
|
61
|
-
- lib/faraday/
|
78
|
+
- lib/faraday/dependency_loader.rb
|
79
|
+
- lib/faraday/encoders/flat_params_encoder.rb
|
80
|
+
- lib/faraday/encoders/nested_params_encoder.rb
|
62
81
|
- lib/faraday/error.rb
|
82
|
+
- lib/faraday/file_part.rb
|
83
|
+
- lib/faraday/logging/formatter.rb
|
63
84
|
- lib/faraday/middleware.rb
|
85
|
+
- lib/faraday/middleware_registry.rb
|
64
86
|
- lib/faraday/options.rb
|
87
|
+
- lib/faraday/options/connection_options.rb
|
88
|
+
- lib/faraday/options/env.rb
|
89
|
+
- lib/faraday/options/proxy_options.rb
|
90
|
+
- lib/faraday/options/request_options.rb
|
91
|
+
- lib/faraday/options/ssl_options.rb
|
92
|
+
- lib/faraday/param_part.rb
|
65
93
|
- lib/faraday/parameters.rb
|
66
94
|
- lib/faraday/rack_builder.rb
|
67
95
|
- lib/faraday/request.rb
|
@@ -75,65 +103,80 @@ files:
|
|
75
103
|
- lib/faraday/response.rb
|
76
104
|
- lib/faraday/response/logger.rb
|
77
105
|
- lib/faraday/response/raise_error.rb
|
78
|
-
- lib/faraday/upload_io.rb
|
79
106
|
- lib/faraday/utils.rb
|
80
|
-
-
|
107
|
+
- lib/faraday/utils/headers.rb
|
108
|
+
- lib/faraday/utils/params_hash.rb
|
109
|
+
- spec/external_adapters/faraday_specs_setup.rb
|
110
|
+
- spec/faraday/adapter/em_http_spec.rb
|
111
|
+
- spec/faraday/adapter/em_synchrony_spec.rb
|
112
|
+
- spec/faraday/adapter/excon_spec.rb
|
113
|
+
- spec/faraday/adapter/httpclient_spec.rb
|
114
|
+
- spec/faraday/adapter/net_http_persistent_spec.rb
|
115
|
+
- spec/faraday/adapter/net_http_spec.rb
|
116
|
+
- spec/faraday/adapter/patron_spec.rb
|
117
|
+
- spec/faraday/adapter/rack_spec.rb
|
118
|
+
- spec/faraday/adapter/test_spec.rb
|
119
|
+
- spec/faraday/adapter/typhoeus_spec.rb
|
120
|
+
- spec/faraday/adapter_registry_spec.rb
|
121
|
+
- spec/faraday/adapter_spec.rb
|
122
|
+
- spec/faraday/composite_read_io_spec.rb
|
123
|
+
- spec/faraday/connection_spec.rb
|
81
124
|
- spec/faraday/error_spec.rb
|
125
|
+
- spec/faraday/middleware_spec.rb
|
126
|
+
- spec/faraday/options/env_spec.rb
|
127
|
+
- spec/faraday/options/options_spec.rb
|
128
|
+
- spec/faraday/options/proxy_options_spec.rb
|
129
|
+
- spec/faraday/options/request_options_spec.rb
|
130
|
+
- spec/faraday/params_encoders/flat_spec.rb
|
131
|
+
- spec/faraday/params_encoders/nested_spec.rb
|
132
|
+
- spec/faraday/rack_builder_spec.rb
|
133
|
+
- spec/faraday/request/authorization_spec.rb
|
134
|
+
- spec/faraday/request/instrumentation_spec.rb
|
135
|
+
- spec/faraday/request/multipart_spec.rb
|
136
|
+
- spec/faraday/request/retry_spec.rb
|
137
|
+
- spec/faraday/request/url_encoded_spec.rb
|
138
|
+
- spec/faraday/request_spec.rb
|
139
|
+
- spec/faraday/response/logger_spec.rb
|
140
|
+
- spec/faraday/response/middleware_spec.rb
|
82
141
|
- spec/faraday/response/raise_error_spec.rb
|
142
|
+
- spec/faraday/response_spec.rb
|
143
|
+
- spec/faraday/utils/headers_spec.rb
|
144
|
+
- spec/faraday/utils_spec.rb
|
145
|
+
- spec/faraday_spec.rb
|
83
146
|
- spec/spec_helper.rb
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
- test/adapters/net_http_test.rb
|
93
|
-
- test/adapters/patron_test.rb
|
94
|
-
- test/adapters/rack_test.rb
|
95
|
-
- test/adapters/test_middleware_test.rb
|
96
|
-
- test/adapters/typhoeus_test.rb
|
97
|
-
- test/authentication_middleware_test.rb
|
98
|
-
- test/composite_read_io_test.rb
|
99
|
-
- test/connection_test.rb
|
100
|
-
- test/env_test.rb
|
101
|
-
- test/helper.rb
|
102
|
-
- test/live_server.rb
|
103
|
-
- test/middleware/instrumentation_test.rb
|
104
|
-
- test/middleware/retry_test.rb
|
105
|
-
- test/middleware_stack_test.rb
|
106
|
-
- test/multibyte.txt
|
107
|
-
- test/options_test.rb
|
108
|
-
- test/parameters_test.rb
|
109
|
-
- test/request_middleware_test.rb
|
110
|
-
- test/response_middleware_test.rb
|
111
|
-
- test/strawberry.rb
|
112
|
-
- test/utils_test.rb
|
147
|
+
- spec/support/disabling_stub.rb
|
148
|
+
- spec/support/fake_safe_buffer.rb
|
149
|
+
- spec/support/helper_methods.rb
|
150
|
+
- spec/support/shared_examples/adapter.rb
|
151
|
+
- spec/support/shared_examples/params_encoder.rb
|
152
|
+
- spec/support/shared_examples/request_method.rb
|
153
|
+
- spec/support/streaming_response_checker.rb
|
154
|
+
- spec/support/webmock_rack_app.rb
|
113
155
|
homepage: https://lostisland.github.io/faraday
|
114
156
|
licenses:
|
115
157
|
- MIT
|
116
158
|
metadata:
|
117
159
|
homepage_uri: https://lostisland.github.io/faraday
|
118
|
-
changelog_uri: https://github.com/lostisland/faraday/
|
119
|
-
source_code_uri: https://github.com/lostisland/faraday
|
160
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.1.0
|
161
|
+
source_code_uri: https://github.com/lostisland/faraday
|
120
162
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
121
163
|
post_install_message:
|
122
164
|
rdoc_options: []
|
123
165
|
require_paths:
|
124
166
|
- lib
|
167
|
+
- spec/external_adapters
|
125
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
126
169
|
requirements:
|
127
170
|
- - ">="
|
128
171
|
- !ruby/object:Gem::Version
|
129
|
-
version: '
|
172
|
+
version: '2.4'
|
130
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
174
|
requirements:
|
132
175
|
- - ">="
|
133
176
|
- !ruby/object:Gem::Version
|
134
177
|
version: '0'
|
135
178
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
179
|
+
rubygems_version: 3.0.3
|
137
180
|
signing_key:
|
138
181
|
specification_version: 4
|
139
182
|
summary: HTTP/REST API client library.
|
data/lib/faraday/deprecate.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
# @param new_klass [Class] new Klass to use
|
5
|
-
#
|
6
|
-
# @return [Class] A modified version of new_klass that warns on
|
7
|
-
# usage about deprecation.
|
8
|
-
# @see Faraday::Deprecate
|
9
|
-
module DeprecatedClass
|
10
|
-
def self.proxy_class(origclass, ver = '1.0')
|
11
|
-
proxy = Class.new(origclass) do
|
12
|
-
const_set("ORIG_CLASS", origclass)
|
13
|
-
|
14
|
-
class << self
|
15
|
-
extend Faraday::Deprecate
|
16
|
-
|
17
|
-
def ===(other)
|
18
|
-
(superclass == const_get("ORIG_CLASS") && other.is_a?(superclass)) || super
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
|
23
|
-
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
|
24
|
-
proxy
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# Deprecation using semver instead of date, based on Gem::Deprecate
|
29
|
-
# Provides a single method +deprecate+ to be used to declare when
|
30
|
-
# something is going away.
|
31
|
-
#
|
32
|
-
# class Legacy
|
33
|
-
# def self.klass_method
|
34
|
-
# # ...
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# def instance_method
|
38
|
-
# # ...
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# extend Faraday::Deprecate
|
42
|
-
# deprecate :instance_method, "X.z", '1.0'
|
43
|
-
#
|
44
|
-
# class << self
|
45
|
-
# extend Faraday::Deprecate
|
46
|
-
# deprecate :klass_method, :none, '1.0'
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
module Deprecate
|
50
|
-
def self.skip # :nodoc:
|
51
|
-
@skip ||= begin
|
52
|
-
case ENV['FARADAY_DEPRECATE'].to_s.downcase
|
53
|
-
when '1', 'warn' then :warn
|
54
|
-
else :skip
|
55
|
-
end
|
56
|
-
end
|
57
|
-
@skip == :skip
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.skip=(value) # :nodoc:
|
61
|
-
@skip = value ? :skip : :warn
|
62
|
-
end
|
63
|
-
|
64
|
-
# Temporarily turn off warnings. Intended for tests only.
|
65
|
-
def skip_during
|
66
|
-
original = Faraday::Deprecate.skip
|
67
|
-
Faraday::Deprecate.skip, = true
|
68
|
-
yield
|
69
|
-
ensure
|
70
|
-
Faraday::Deprecate.skip = original
|
71
|
-
end
|
72
|
-
|
73
|
-
# Simple deprecation method that deprecates +name+ by wrapping it up
|
74
|
-
# in a dummy method. It warns on each call to the dummy method
|
75
|
-
# telling the user of +repl+ (unless +repl+ is :none) and the
|
76
|
-
# semver that it is planned to go away.
|
77
|
-
# @param name [Symbol] the method symbol to deprecate
|
78
|
-
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
|
79
|
-
# alert the user that no replacemtent is present.
|
80
|
-
# @param ver [String] the semver the method will be removed.
|
81
|
-
def deprecate(name, repl, ver)
|
82
|
-
class_eval do
|
83
|
-
gem_ver = Gem::Version.new(ver)
|
84
|
-
old = "_deprecated_#{name}"
|
85
|
-
alias_method old, name
|
86
|
-
define_method name do |*args, &block|
|
87
|
-
mod = is_a? Module
|
88
|
-
target = mod ? "#{self}." : "#{self.class}#"
|
89
|
-
target_message = if name == :inherited
|
90
|
-
"Inheriting #{self}"
|
91
|
-
else
|
92
|
-
"#{target}#{name}"
|
93
|
-
end
|
94
|
-
|
95
|
-
msg = [
|
96
|
-
"NOTE: #{target_message} is deprecated",
|
97
|
-
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
|
98
|
-
"It will be removed in or after version #{gem_ver}",
|
99
|
-
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
|
100
|
-
]
|
101
|
-
warn "#{msg.join}." unless Faraday::Deprecate.skip
|
102
|
-
send old, *args, &block
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
module_function :deprecate, :skip_during
|
108
|
-
end
|
109
|
-
end
|
data/lib/faraday/upload_io.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'composite_io'
|
3
|
-
require 'parts'
|
4
|
-
require 'stringio'
|
5
|
-
rescue LoadError
|
6
|
-
$stderr.puts "Install the multipart-post gem."
|
7
|
-
raise
|
8
|
-
end
|
9
|
-
|
10
|
-
module Faraday
|
11
|
-
# Similar but not compatible with ::CompositeReadIO provided by multipart-post.
|
12
|
-
class CompositeReadIO
|
13
|
-
def initialize(*parts)
|
14
|
-
@parts = parts.flatten
|
15
|
-
@ios = @parts.map { |part| part.to_io }
|
16
|
-
@index = 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def length
|
20
|
-
@parts.inject(0) { |sum, part| sum + part.length }
|
21
|
-
end
|
22
|
-
|
23
|
-
def rewind
|
24
|
-
@ios.each { |io| io.rewind }
|
25
|
-
@index = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
# Read from IOs in order until `length` bytes have been received.
|
29
|
-
def read(length = nil, outbuf = nil)
|
30
|
-
got_result = false
|
31
|
-
outbuf = outbuf ? outbuf.replace("") : ""
|
32
|
-
|
33
|
-
while io = current_io
|
34
|
-
if result = io.read(length)
|
35
|
-
got_result ||= !result.nil?
|
36
|
-
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
37
|
-
outbuf << result
|
38
|
-
length -= result.length if length
|
39
|
-
break if length == 0
|
40
|
-
end
|
41
|
-
advance_io
|
42
|
-
end
|
43
|
-
(!got_result && length) ? nil : outbuf
|
44
|
-
end
|
45
|
-
|
46
|
-
def close
|
47
|
-
@ios.each { |io| io.close }
|
48
|
-
end
|
49
|
-
|
50
|
-
def ensure_open_and_readable
|
51
|
-
# Rubinius compatibility
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def current_io
|
57
|
-
@ios[@index]
|
58
|
-
end
|
59
|
-
|
60
|
-
def advance_io
|
61
|
-
@index += 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
UploadIO = ::UploadIO
|
66
|
-
Parts = ::Parts
|
67
|
-
end
|