faraday 1.0.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +299 -1
- data/LICENSE.md +1 -1
- data/README.md +35 -23
- data/Rakefile +6 -1
- data/examples/client_spec.rb +68 -14
- data/examples/client_test.rb +80 -15
- data/lib/faraday/adapter/test.rb +117 -52
- data/lib/faraday/adapter.rb +7 -21
- data/lib/faraday/adapter_registry.rb +3 -1
- data/lib/faraday/connection.rb +75 -133
- data/lib/faraday/encoders/flat_params_encoder.rb +9 -2
- data/lib/faraday/encoders/nested_params_encoder.rb +20 -8
- data/lib/faraday/error.rb +39 -6
- data/lib/faraday/logging/formatter.rb +28 -15
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +59 -5
- data/lib/faraday/middleware_registry.rb +17 -63
- data/lib/faraday/options/connection_options.rb +7 -6
- data/lib/faraday/options/env.rb +85 -62
- data/lib/faraday/options/proxy_options.rb +11 -3
- data/lib/faraday/options/request_options.rb +7 -6
- data/lib/faraday/options/ssl_options.rb +56 -45
- data/lib/faraday/options.rb +11 -14
- data/lib/faraday/rack_builder.rb +35 -32
- data/lib/faraday/request/authorization.rb +37 -36
- data/lib/faraday/request/instrumentation.rb +5 -1
- data/lib/faraday/request/json.rb +70 -0
- data/lib/faraday/request/url_encoded.rb +8 -2
- data/lib/faraday/request.rb +22 -29
- data/lib/faraday/response/json.rb +74 -0
- data/lib/faraday/response/logger.rb +8 -4
- data/lib/faraday/response/raise_error.rb +43 -3
- data/lib/faraday/response.rb +10 -23
- data/lib/faraday/utils/headers.rb +17 -6
- data/lib/faraday/utils.rb +22 -10
- data/lib/faraday/version.rb +5 -0
- data/lib/faraday.rb +49 -58
- data/spec/faraday/adapter/test_spec.rb +442 -0
- data/spec/faraday/connection_spec.rb +207 -90
- data/spec/faraday/error_spec.rb +45 -5
- data/spec/faraday/middleware_registry_spec.rb +31 -0
- data/spec/faraday/middleware_spec.rb +193 -6
- data/spec/faraday/options/env_spec.rb +8 -2
- data/spec/faraday/options/options_spec.rb +1 -1
- data/spec/faraday/options/proxy_options_spec.rb +15 -0
- data/spec/faraday/params_encoders/flat_spec.rb +8 -0
- data/spec/faraday/params_encoders/nested_spec.rb +18 -1
- data/spec/faraday/rack_builder_spec.rb +171 -50
- data/spec/faraday/request/authorization_spec.rb +54 -24
- data/spec/faraday/request/instrumentation_spec.rb +5 -7
- data/spec/faraday/request/json_spec.rb +199 -0
- data/spec/faraday/request/url_encoded_spec.rb +25 -2
- data/spec/faraday/request_spec.rb +11 -10
- data/spec/faraday/response/json_spec.rb +206 -0
- data/spec/faraday/response/logger_spec.rb +38 -0
- data/spec/faraday/response/raise_error_spec.rb +149 -0
- data/spec/faraday/response_spec.rb +3 -1
- data/spec/faraday/utils/headers_spec.rb +31 -4
- data/spec/faraday/utils_spec.rb +63 -1
- data/spec/faraday_spec.rb +10 -4
- data/spec/spec_helper.rb +6 -5
- data/spec/support/fake_safe_buffer.rb +1 -1
- data/spec/support/faraday_middleware_subclasses.rb +18 -0
- data/spec/support/helper_methods.rb +0 -37
- data/spec/support/shared_examples/adapter.rb +4 -3
- data/spec/support/shared_examples/request_method.rb +60 -31
- metadata +34 -44
- data/UPGRADING.md +0 -55
- data/lib/faraday/adapter/em_http.rb +0 -285
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
- data/lib/faraday/adapter/em_synchrony.rb +0 -150
- data/lib/faraday/adapter/excon.rb +0 -124
- data/lib/faraday/adapter/httpclient.rb +0 -151
- data/lib/faraday/adapter/net_http.rb +0 -209
- data/lib/faraday/adapter/net_http_persistent.rb +0 -91
- data/lib/faraday/adapter/patron.rb +0 -132
- data/lib/faraday/adapter/rack.rb +0 -75
- data/lib/faraday/adapter/typhoeus.rb +0 -15
- data/lib/faraday/autoload.rb +0 -95
- data/lib/faraday/dependency_loader.rb +0 -37
- data/lib/faraday/file_part.rb +0 -128
- data/lib/faraday/param_part.rb +0 -53
- data/lib/faraday/request/basic_authentication.rb +0 -20
- data/lib/faraday/request/multipart.rb +0 -99
- data/lib/faraday/request/retry.rb +0 -239
- data/lib/faraday/request/token_authentication.rb +0 -20
- data/spec/faraday/adapter/em_http_spec.rb +0 -47
- data/spec/faraday/adapter/em_synchrony_spec.rb +0 -16
- data/spec/faraday/adapter/excon_spec.rb +0 -49
- data/spec/faraday/adapter/httpclient_spec.rb +0 -73
- data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
- data/spec/faraday/adapter/net_http_spec.rb +0 -64
- data/spec/faraday/adapter/patron_spec.rb +0 -18
- data/spec/faraday/adapter/rack_spec.rb +0 -8
- data/spec/faraday/adapter/typhoeus_spec.rb +0 -7
- data/spec/faraday/composite_read_io_spec.rb +0 -80
- data/spec/faraday/request/multipart_spec.rb +0 -274
- data/spec/faraday/request/retry_spec.rb +0 -242
- data/spec/faraday/response/middleware_spec.rb +0 -52
- data/spec/support/webmock_rack_app.rb +0 -68
data/spec/faraday/utils_spec.rb
CHANGED
|
@@ -4,7 +4,7 @@ RSpec.describe Faraday::Utils do
|
|
|
4
4
|
describe 'headers parsing' do
|
|
5
5
|
let(:multi_response_headers) do
|
|
6
6
|
"HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
|
|
7
|
-
|
|
7
|
+
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
it 'parse headers for aggregated responses' do
|
|
@@ -53,4 +53,66 @@ RSpec.describe Faraday::Utils do
|
|
|
53
53
|
expect(headers).not_to have_key('authorization')
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
|
+
|
|
57
|
+
describe '.deep_merge!' do
|
|
58
|
+
let(:connection_options) { Faraday::ConnectionOptions.new }
|
|
59
|
+
let(:url) do
|
|
60
|
+
{
|
|
61
|
+
url: 'http://example.com/abc',
|
|
62
|
+
headers: { 'Mime-Version' => '1.0' },
|
|
63
|
+
request: { oauth: { consumer_key: 'anonymous' } },
|
|
64
|
+
ssl: { version: '2' }
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'recursively merges the headers' do
|
|
69
|
+
connection_options.headers = { user_agent: 'My Agent 1.0' }
|
|
70
|
+
deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
|
|
71
|
+
|
|
72
|
+
expect(deep_merge.headers).to eq('Mime-Version' => '1.0', user_agent: 'My Agent 1.0')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context 'when a target hash has an Options Struct value' do
|
|
76
|
+
let(:request) do
|
|
77
|
+
{
|
|
78
|
+
params_encoder: nil,
|
|
79
|
+
proxy: nil,
|
|
80
|
+
bind: nil,
|
|
81
|
+
timeout: nil,
|
|
82
|
+
open_timeout: nil,
|
|
83
|
+
read_timeout: nil,
|
|
84
|
+
write_timeout: nil,
|
|
85
|
+
boundary: nil,
|
|
86
|
+
oauth: { consumer_key: 'anonymous' },
|
|
87
|
+
context: nil,
|
|
88
|
+
on_data: nil
|
|
89
|
+
}
|
|
90
|
+
end
|
|
91
|
+
let(:ssl) do
|
|
92
|
+
{
|
|
93
|
+
verify: nil,
|
|
94
|
+
ca_file: nil,
|
|
95
|
+
ca_path: nil,
|
|
96
|
+
verify_mode: nil,
|
|
97
|
+
cert_store: nil,
|
|
98
|
+
client_cert: nil,
|
|
99
|
+
client_key: nil,
|
|
100
|
+
certificate: nil,
|
|
101
|
+
private_key: nil,
|
|
102
|
+
verify_depth: nil,
|
|
103
|
+
version: '2',
|
|
104
|
+
min_version: nil,
|
|
105
|
+
max_version: nil,
|
|
106
|
+
verify_hostname: nil
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'does not overwrite an Options Struct value' do
|
|
111
|
+
deep_merge = Faraday::Utils.deep_merge!(connection_options, url)
|
|
112
|
+
|
|
113
|
+
expect(deep_merge.request.to_h).to eq(request)
|
|
114
|
+
expect(deep_merge.ssl.to_h).to eq(ssl)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
56
118
|
end
|
data/spec/faraday_spec.rb
CHANGED
|
@@ -18,10 +18,16 @@ RSpec.describe Faraday do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
it 'uses method_missing on Faraday if there is no proxyable method' do
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
expected_message =
|
|
22
|
+
if RUBY_VERSION >= '3.4'
|
|
23
|
+
"undefined method 'this_method_does_not_exist' for module Faraday"
|
|
24
|
+
elsif RUBY_VERSION >= '3.3'
|
|
25
|
+
"undefined method `this_method_does_not_exist' for module Faraday"
|
|
26
|
+
else
|
|
27
|
+
"undefined method `this_method_does_not_exist' for Faraday:Module"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
expect { Faraday.this_method_does_not_exist }.to raise_error(NoMethodError, expected_message)
|
|
25
31
|
end
|
|
26
32
|
|
|
27
33
|
it 'proxied methods can be accessed' do
|
data/spec/spec_helper.rb
CHANGED
|
@@ -29,14 +29,15 @@ SimpleCov.start do
|
|
|
29
29
|
minimum_coverage_by_file 26
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
# Ensure all /lib files are loaded
|
|
33
|
-
# so they will be included in the test coverage report.
|
|
34
|
-
Dir['./lib/**/*.rb'].sort.each { |file| require file }
|
|
35
|
-
|
|
36
32
|
require 'faraday'
|
|
37
33
|
require 'pry'
|
|
38
34
|
|
|
39
|
-
|
|
35
|
+
# Ensure all /lib files are loaded
|
|
36
|
+
# so they will be included in the test coverage report.
|
|
37
|
+
Dir['./lib/**/*.rb'].each { |file| require file }
|
|
38
|
+
|
|
39
|
+
# Load all Rspec support files
|
|
40
|
+
Dir['./spec/support/**/*.rb'].each { |file| require file }
|
|
40
41
|
|
|
41
42
|
RSpec.configure do |config|
|
|
42
43
|
# rspec-expectations config goes here. You can use an alternate
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FaradayMiddlewareSubclasses
|
|
4
|
+
class SubclassNoOptions < Faraday::Middleware
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class SubclassOneOption < Faraday::Middleware
|
|
8
|
+
DEFAULT_OPTIONS = { some_other_option: false }.freeze
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class SubclassTwoOptions < Faraday::Middleware
|
|
12
|
+
DEFAULT_OPTIONS = { some_option: true, some_other_option: false }.freeze
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Faraday::Response.register_middleware(no_options: FaradayMiddlewareSubclasses::SubclassNoOptions)
|
|
17
|
+
Faraday::Response.register_middleware(one_option: FaradayMiddlewareSubclasses::SubclassOneOption)
|
|
18
|
+
Faraday::Response.register_middleware(two_options: FaradayMiddlewareSubclasses::SubclassTwoOptions)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'multipart_parser/reader'
|
|
4
|
-
|
|
5
3
|
module Faraday
|
|
6
4
|
module HelperMethods
|
|
7
5
|
def self.included(base)
|
|
@@ -86,41 +84,6 @@ module Faraday
|
|
|
86
84
|
end
|
|
87
85
|
end
|
|
88
86
|
|
|
89
|
-
def multipart_file
|
|
90
|
-
Faraday::FilePart.new(__FILE__, 'text/x-ruby')
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# parse boundary out of a Content-Type header like:
|
|
94
|
-
# Content-Type: multipart/form-data; boundary=gc0p4Jq0M2Yt08jU534c0p
|
|
95
|
-
def parse_multipart_boundary(ctype)
|
|
96
|
-
MultipartParser::Reader.extract_boundary_value(ctype)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# parse a multipart MIME message, returning a hash of any multipart errors
|
|
100
|
-
def parse_multipart(boundary, body)
|
|
101
|
-
reader = MultipartParser::Reader.new(boundary)
|
|
102
|
-
result = { errors: [], parts: [] }
|
|
103
|
-
def result.part(name)
|
|
104
|
-
hash = self[:parts].detect { |h| h[:part].name == name }
|
|
105
|
-
[hash[:part], hash[:body].join]
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
reader.on_part do |part|
|
|
109
|
-
result[:parts] << thispart = {
|
|
110
|
-
part: part,
|
|
111
|
-
body: []
|
|
112
|
-
}
|
|
113
|
-
part.on_data do |chunk|
|
|
114
|
-
thispart[:body] << chunk
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
reader.on_error do |msg|
|
|
118
|
-
result[:errors] << msg
|
|
119
|
-
end
|
|
120
|
-
reader.write(body)
|
|
121
|
-
result
|
|
122
|
-
end
|
|
123
|
-
|
|
124
87
|
def method_with_body?(method)
|
|
125
88
|
self.class.method_with_body?(method)
|
|
126
89
|
end
|
|
@@ -33,20 +33,21 @@ shared_examples 'adapter examples' do |**options|
|
|
|
33
33
|
|
|
34
34
|
let(:protocol) { ssl_mode? ? 'https' : 'http' }
|
|
35
35
|
let(:remote) { "#{protocol}://example.com" }
|
|
36
|
+
let(:stub_remote) { remote }
|
|
36
37
|
|
|
37
38
|
let(:conn) do
|
|
38
39
|
conn_options[:ssl] ||= {}
|
|
39
|
-
conn_options[:ssl][:ca_file] ||= ENV
|
|
40
|
+
conn_options[:ssl][:ca_file] ||= ENV.fetch('SSL_FILE', nil)
|
|
41
|
+
conn_options[:ssl][:verify_hostname] ||= ENV['SSL_VERIFY_HOSTNAME'] == 'yes'
|
|
40
42
|
|
|
41
43
|
Faraday.new(remote, conn_options) do |conn|
|
|
42
|
-
conn.request :multipart
|
|
43
44
|
conn.request :url_encoded
|
|
44
45
|
conn.response :raise_error
|
|
45
46
|
conn.adapter described_class, *adapter_options
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
49
|
|
|
49
|
-
let!(:request_stub) { stub_request(http_method,
|
|
50
|
+
let!(:request_stub) { stub_request(http_method, stub_remote) }
|
|
50
51
|
|
|
51
52
|
after do
|
|
52
53
|
expect(request_stub).to have_been_requested unless request_stub.disabled?
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
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
|
+
|
|
3
17
|
shared_examples 'a request method' do |http_method|
|
|
4
18
|
let(:query_or_body) { method_with_body?(http_method) ? :body : :query }
|
|
5
19
|
let(:response) { conn.public_send(http_method, '/') }
|
|
@@ -13,8 +27,8 @@ shared_examples 'a request method' do |http_method|
|
|
|
13
27
|
end
|
|
14
28
|
|
|
15
29
|
it 'handles headers with multiple values' do
|
|
16
|
-
request_stub.to_return(headers: { 'Set-Cookie' => '
|
|
17
|
-
expect(response.headers['set-cookie']).to eq('
|
|
30
|
+
request_stub.to_return(headers: { 'Set-Cookie' => 'name=value' })
|
|
31
|
+
expect(response.headers['set-cookie']).to eq('name=value')
|
|
18
32
|
end
|
|
19
33
|
|
|
20
34
|
it 'retrieves the response headers' do
|
|
@@ -65,7 +79,7 @@ shared_examples 'a request method' do |http_method|
|
|
|
65
79
|
|
|
66
80
|
on_feature :request_body_on_query_methods do
|
|
67
81
|
it 'sends request body' do
|
|
68
|
-
request_stub.with(
|
|
82
|
+
request_stub.with({ body: 'test' })
|
|
69
83
|
res = if query_or_body == :body
|
|
70
84
|
conn.public_send(http_method, '/', 'test')
|
|
71
85
|
else
|
|
@@ -79,7 +93,7 @@ shared_examples 'a request method' do |http_method|
|
|
|
79
93
|
|
|
80
94
|
it 'sends url encoded parameters' do
|
|
81
95
|
payload = { name: 'zack' }
|
|
82
|
-
request_stub.with(
|
|
96
|
+
request_stub.with({ query_or_body => payload })
|
|
83
97
|
res = conn.public_send(http_method, '/', payload)
|
|
84
98
|
if query_or_body == :query
|
|
85
99
|
expect(res.env.request_body).to be_nil
|
|
@@ -90,7 +104,7 @@ shared_examples 'a request method' do |http_method|
|
|
|
90
104
|
|
|
91
105
|
it 'sends url encoded nested parameters' do
|
|
92
106
|
payload = { name: { first: 'zack' } }
|
|
93
|
-
request_stub.with(
|
|
107
|
+
request_stub.with({ query_or_body => payload })
|
|
94
108
|
conn.public_send(http_method, '/', payload)
|
|
95
109
|
end
|
|
96
110
|
|
|
@@ -112,19 +126,6 @@ shared_examples 'a request method' do |http_method|
|
|
|
112
126
|
expect { conn.public_send(http_method, '/') }.to raise_error(exc)
|
|
113
127
|
end
|
|
114
128
|
|
|
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 =~ /RubyMultipartPost/
|
|
123
|
-
end
|
|
124
|
-
conn.public_send(http_method, '/', payload)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
129
|
on_feature :reason_phrase_parse do
|
|
129
130
|
it 'parses the reason phrase' do
|
|
130
131
|
request_stub.to_return(status: [200, 'OK'])
|
|
@@ -152,12 +153,19 @@ shared_examples 'a request method' do |http_method|
|
|
|
152
153
|
let(:streamed) { [] }
|
|
153
154
|
|
|
154
155
|
context 'when response is empty' do
|
|
155
|
-
it do
|
|
156
|
+
it 'handles streaming' do
|
|
157
|
+
env = nil
|
|
156
158
|
conn.public_send(http_method, '/') do |req|
|
|
157
|
-
req.options.on_data = proc
|
|
159
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
|
160
|
+
streamed << [chunk, size]
|
|
161
|
+
env ||= block_env
|
|
162
|
+
end
|
|
158
163
|
end
|
|
159
164
|
|
|
160
165
|
expect(streamed).to eq([['', 0]])
|
|
166
|
+
# TODO: enable this after updating all existing adapters to the new streaming API
|
|
167
|
+
# expect(env).to be_a(Faraday::Env)
|
|
168
|
+
# expect(env.status).to eq(200)
|
|
161
169
|
end
|
|
162
170
|
end
|
|
163
171
|
|
|
@@ -165,12 +173,19 @@ shared_examples 'a request method' do |http_method|
|
|
|
165
173
|
before { request_stub.to_return(body: big_string) }
|
|
166
174
|
|
|
167
175
|
it 'handles streaming' do
|
|
176
|
+
env = nil
|
|
168
177
|
response = conn.public_send(http_method, '/') do |req|
|
|
169
|
-
req.options.on_data = proc
|
|
178
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
|
179
|
+
streamed << [chunk, size]
|
|
180
|
+
env ||= block_env
|
|
181
|
+
end
|
|
170
182
|
end
|
|
171
183
|
|
|
172
184
|
expect(response.body).to eq('')
|
|
173
185
|
check_streaming_response(streamed, chunk_size: 16 * 1024)
|
|
186
|
+
# TODO: enable this after updating all existing adapters to the new streaming API
|
|
187
|
+
# expect(env).to be_a(Faraday::Env)
|
|
188
|
+
# expect(env.status).to eq(200)
|
|
174
189
|
end
|
|
175
190
|
end
|
|
176
191
|
end
|
|
@@ -185,11 +200,11 @@ shared_examples 'a request method' do |http_method|
|
|
|
185
200
|
@payload2 = { b: '2' }
|
|
186
201
|
|
|
187
202
|
request_stub
|
|
188
|
-
.with(
|
|
203
|
+
.with({ query_or_body => @payload1 })
|
|
189
204
|
.to_return(body: @payload1.to_json)
|
|
190
205
|
|
|
191
206
|
stub_request(http_method, remote)
|
|
192
|
-
.with(
|
|
207
|
+
.with({ query_or_body => @payload2 })
|
|
193
208
|
.to_return(body: @payload2.to_json)
|
|
194
209
|
|
|
195
210
|
conn.in_parallel do
|
|
@@ -218,17 +233,31 @@ shared_examples 'a request method' do |http_method|
|
|
|
218
233
|
end
|
|
219
234
|
end
|
|
220
235
|
|
|
221
|
-
|
|
222
|
-
|
|
236
|
+
context 'when a proxy is provided as option' do
|
|
237
|
+
before do
|
|
238
|
+
conn_options[:proxy] = 'http://env-proxy.com:80'
|
|
239
|
+
end
|
|
223
240
|
|
|
224
|
-
|
|
225
|
-
expect(res.status).to eq(200)
|
|
241
|
+
include_examples 'proxy examples'
|
|
226
242
|
end
|
|
227
243
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
request_stub.to_return(status: 407)
|
|
244
|
+
context 'when http_proxy env variable is set' do
|
|
245
|
+
let(:proxy_url) { 'http://env-proxy.com:80' }
|
|
231
246
|
|
|
232
|
-
|
|
247
|
+
around do |example|
|
|
248
|
+
with_env 'http_proxy' => proxy_url do
|
|
249
|
+
example.run
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
include_examples 'proxy examples'
|
|
254
|
+
|
|
255
|
+
context 'when the env proxy is ignored' do
|
|
256
|
+
around do |example|
|
|
257
|
+
with_env_proxy_disabled(&example)
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
include_examples 'proxy examples'
|
|
261
|
+
end
|
|
233
262
|
end
|
|
234
263
|
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: 2.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- "@technoweenie"
|
|
@@ -10,28 +10,42 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
16
|
+
name: faraday-net_http
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
19
|
- - ">="
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
21
|
+
version: '2.0'
|
|
22
22
|
- - "<"
|
|
23
23
|
- !ruby/object:Gem::Version
|
|
24
|
-
version: '3'
|
|
24
|
+
version: '3.2'
|
|
25
25
|
type: :runtime
|
|
26
26
|
prerelease: false
|
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
|
28
28
|
requirements:
|
|
29
29
|
- - ">="
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '
|
|
31
|
+
version: '2.0'
|
|
32
32
|
- - "<"
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '3'
|
|
34
|
+
version: '3.2'
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: logger
|
|
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,32 +56,18 @@ files:
|
|
|
42
56
|
- LICENSE.md
|
|
43
57
|
- README.md
|
|
44
58
|
- Rakefile
|
|
45
|
-
- UPGRADING.md
|
|
46
59
|
- examples/client_spec.rb
|
|
47
60
|
- examples/client_test.rb
|
|
48
61
|
- lib/faraday.rb
|
|
49
62
|
- lib/faraday/adapter.rb
|
|
50
|
-
- lib/faraday/adapter/em_http.rb
|
|
51
|
-
- lib/faraday/adapter/em_http_ssl_patch.rb
|
|
52
|
-
- lib/faraday/adapter/em_synchrony.rb
|
|
53
|
-
- lib/faraday/adapter/em_synchrony/parallel_manager.rb
|
|
54
|
-
- lib/faraday/adapter/excon.rb
|
|
55
|
-
- lib/faraday/adapter/httpclient.rb
|
|
56
|
-
- lib/faraday/adapter/net_http.rb
|
|
57
|
-
- lib/faraday/adapter/net_http_persistent.rb
|
|
58
|
-
- lib/faraday/adapter/patron.rb
|
|
59
|
-
- lib/faraday/adapter/rack.rb
|
|
60
63
|
- lib/faraday/adapter/test.rb
|
|
61
|
-
- lib/faraday/adapter/typhoeus.rb
|
|
62
64
|
- lib/faraday/adapter_registry.rb
|
|
63
|
-
- lib/faraday/autoload.rb
|
|
64
65
|
- lib/faraday/connection.rb
|
|
65
|
-
- lib/faraday/dependency_loader.rb
|
|
66
66
|
- lib/faraday/encoders/flat_params_encoder.rb
|
|
67
67
|
- lib/faraday/encoders/nested_params_encoder.rb
|
|
68
68
|
- lib/faraday/error.rb
|
|
69
|
-
- lib/faraday/file_part.rb
|
|
70
69
|
- lib/faraday/logging/formatter.rb
|
|
70
|
+
- lib/faraday/methods.rb
|
|
71
71
|
- lib/faraday/middleware.rb
|
|
72
72
|
- lib/faraday/middleware_registry.rb
|
|
73
73
|
- lib/faraday/options.rb
|
|
@@ -76,38 +76,28 @@ files:
|
|
|
76
76
|
- lib/faraday/options/proxy_options.rb
|
|
77
77
|
- lib/faraday/options/request_options.rb
|
|
78
78
|
- lib/faraday/options/ssl_options.rb
|
|
79
|
-
- lib/faraday/param_part.rb
|
|
80
79
|
- lib/faraday/parameters.rb
|
|
81
80
|
- lib/faraday/rack_builder.rb
|
|
82
81
|
- lib/faraday/request.rb
|
|
83
82
|
- lib/faraday/request/authorization.rb
|
|
84
|
-
- lib/faraday/request/basic_authentication.rb
|
|
85
83
|
- lib/faraday/request/instrumentation.rb
|
|
86
|
-
- lib/faraday/request/
|
|
87
|
-
- lib/faraday/request/retry.rb
|
|
88
|
-
- lib/faraday/request/token_authentication.rb
|
|
84
|
+
- lib/faraday/request/json.rb
|
|
89
85
|
- lib/faraday/request/url_encoded.rb
|
|
90
86
|
- lib/faraday/response.rb
|
|
87
|
+
- lib/faraday/response/json.rb
|
|
91
88
|
- lib/faraday/response/logger.rb
|
|
92
89
|
- lib/faraday/response/raise_error.rb
|
|
93
90
|
- lib/faraday/utils.rb
|
|
94
91
|
- lib/faraday/utils/headers.rb
|
|
95
92
|
- lib/faraday/utils/params_hash.rb
|
|
93
|
+
- lib/faraday/version.rb
|
|
96
94
|
- spec/external_adapters/faraday_specs_setup.rb
|
|
97
|
-
- spec/faraday/adapter/
|
|
98
|
-
- spec/faraday/adapter/em_synchrony_spec.rb
|
|
99
|
-
- spec/faraday/adapter/excon_spec.rb
|
|
100
|
-
- spec/faraday/adapter/httpclient_spec.rb
|
|
101
|
-
- spec/faraday/adapter/net_http_persistent_spec.rb
|
|
102
|
-
- spec/faraday/adapter/net_http_spec.rb
|
|
103
|
-
- spec/faraday/adapter/patron_spec.rb
|
|
104
|
-
- spec/faraday/adapter/rack_spec.rb
|
|
105
|
-
- spec/faraday/adapter/typhoeus_spec.rb
|
|
95
|
+
- spec/faraday/adapter/test_spec.rb
|
|
106
96
|
- spec/faraday/adapter_registry_spec.rb
|
|
107
97
|
- spec/faraday/adapter_spec.rb
|
|
108
|
-
- spec/faraday/composite_read_io_spec.rb
|
|
109
98
|
- spec/faraday/connection_spec.rb
|
|
110
99
|
- spec/faraday/error_spec.rb
|
|
100
|
+
- spec/faraday/middleware_registry_spec.rb
|
|
111
101
|
- spec/faraday/middleware_spec.rb
|
|
112
102
|
- spec/faraday/options/env_spec.rb
|
|
113
103
|
- spec/faraday/options/options_spec.rb
|
|
@@ -118,12 +108,11 @@ files:
|
|
|
118
108
|
- spec/faraday/rack_builder_spec.rb
|
|
119
109
|
- spec/faraday/request/authorization_spec.rb
|
|
120
110
|
- spec/faraday/request/instrumentation_spec.rb
|
|
121
|
-
- spec/faraday/request/
|
|
122
|
-
- spec/faraday/request/retry_spec.rb
|
|
111
|
+
- spec/faraday/request/json_spec.rb
|
|
123
112
|
- spec/faraday/request/url_encoded_spec.rb
|
|
124
113
|
- spec/faraday/request_spec.rb
|
|
114
|
+
- spec/faraday/response/json_spec.rb
|
|
125
115
|
- spec/faraday/response/logger_spec.rb
|
|
126
|
-
- spec/faraday/response/middleware_spec.rb
|
|
127
116
|
- spec/faraday/response/raise_error_spec.rb
|
|
128
117
|
- spec/faraday/response_spec.rb
|
|
129
118
|
- spec/faraday/utils/headers_spec.rb
|
|
@@ -132,36 +121,37 @@ files:
|
|
|
132
121
|
- spec/spec_helper.rb
|
|
133
122
|
- spec/support/disabling_stub.rb
|
|
134
123
|
- spec/support/fake_safe_buffer.rb
|
|
124
|
+
- spec/support/faraday_middleware_subclasses.rb
|
|
135
125
|
- spec/support/helper_methods.rb
|
|
136
126
|
- spec/support/shared_examples/adapter.rb
|
|
137
127
|
- spec/support/shared_examples/params_encoder.rb
|
|
138
128
|
- spec/support/shared_examples/request_method.rb
|
|
139
129
|
- spec/support/streaming_response_checker.rb
|
|
140
|
-
- spec/support/webmock_rack_app.rb
|
|
141
130
|
homepage: https://lostisland.github.io/faraday
|
|
142
131
|
licenses:
|
|
143
132
|
- MIT
|
|
144
133
|
metadata:
|
|
145
134
|
homepage_uri: https://lostisland.github.io/faraday
|
|
146
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/
|
|
135
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.10.0
|
|
147
136
|
source_code_uri: https://github.com/lostisland/faraday
|
|
148
137
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
|
149
138
|
post_install_message:
|
|
150
139
|
rdoc_options: []
|
|
151
140
|
require_paths:
|
|
152
141
|
- lib
|
|
142
|
+
- spec/external_adapters
|
|
153
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
144
|
requirements:
|
|
155
145
|
- - ">="
|
|
156
146
|
- !ruby/object:Gem::Version
|
|
157
|
-
version: '
|
|
147
|
+
version: '3.0'
|
|
158
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
149
|
requirements:
|
|
160
150
|
- - ">="
|
|
161
151
|
- !ruby/object:Gem::Version
|
|
162
152
|
version: '0'
|
|
163
153
|
requirements: []
|
|
164
|
-
rubygems_version: 3.
|
|
154
|
+
rubygems_version: 3.5.11
|
|
165
155
|
signing_key:
|
|
166
156
|
specification_version: 4
|
|
167
157
|
summary: HTTP/REST API client library.
|
data/UPGRADING.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
## Faraday 1.0
|
|
2
|
-
|
|
3
|
-
### Errors
|
|
4
|
-
* Removes sub-class constants definition from `Faraday::Error`. A sub-class (e.g. `ClientError`) was previously accessible
|
|
5
|
-
either through the `Faraday` module (e.g. `Faraday::ClientError`) or through the `Faraday::Error` class (e.g. `Faraday::Error::ClientError`).
|
|
6
|
-
The latter is no longer available and the former should be used instead, so check your `rescue`s.
|
|
7
|
-
* Introduces a new `Faraday::ServerError` (5xx status codes) alongside the existing `Faraday::ClientError` (4xx status codes).
|
|
8
|
-
Please note `Faraday::ClientError` was previously used for both.
|
|
9
|
-
* Introduces new Errors that describe the most common REST status codes:
|
|
10
|
-
* Faraday::BadRequestError (400)
|
|
11
|
-
* Faraday::UnauthorizedError (401)
|
|
12
|
-
* Faraday::ForbiddenError (403)
|
|
13
|
-
* Faraday::ProxyAuthError (407). Please note this raised a `Faraday::ConnectionFailed` before.
|
|
14
|
-
* Faraday::ConflictError (409)
|
|
15
|
-
* Faraday::UnprocessableEntityError (422)
|
|
16
|
-
* The following error classes have changed the hierarchy to better mirror their real-world usage and semantic meaning:
|
|
17
|
-
* TimeoutError < ServerError (was < ClientError)
|
|
18
|
-
* ConnectionFailed < Error (was < ClientError)
|
|
19
|
-
* SSLError < Error (was < ClientError)
|
|
20
|
-
* ParsingError < Error (was < ClientError)
|
|
21
|
-
* RetriableResponse < Error (was < ClientError)
|
|
22
|
-
|
|
23
|
-
### Custom adapters
|
|
24
|
-
If you have written a custom adapter, please be aware that `env.body` is now an alias to the two new properties `request_body` and `response_body`.
|
|
25
|
-
This should work without you noticing if your adapter inherits from `Faraday::Adapter` and calls `save_response`, but if it doesn't, then please ensure you set the `status` BEFORE the `body` while processing the response.
|
|
26
|
-
|
|
27
|
-
### Others
|
|
28
|
-
* Dropped support for jruby and Rubinius.
|
|
29
|
-
* Officially supports Ruby 2.4+
|
|
30
|
-
* In order to specify the adapter you now MUST use the `#adapter` method on the connection builder. If you don't do so and your adapter inherits from `Faraday::Adapter` then Faraday will raise an exception. Otherwise, Faraday will automatically push the default adapter at the end of the stack causing your request to be executed twice.
|
|
31
|
-
```ruby
|
|
32
|
-
class OfficialAdapter < Faraday::Adapter
|
|
33
|
-
...
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class MyAdapter
|
|
37
|
-
...
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# This will raise an exception
|
|
41
|
-
conn = Faraday.new(...) do |f|
|
|
42
|
-
f.use OfficialAdapter
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# This will cause Faraday inserting the default adapter at the end of the stack
|
|
46
|
-
conn = Faraday.new(...) do |f|
|
|
47
|
-
f.use MyAdapter
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# You MUST use `adapter` method
|
|
51
|
-
conn = Faraday.new(...) do |f|
|
|
52
|
-
f.adapter AnyAdapter
|
|
53
|
-
end
|
|
54
|
-
```
|
|
55
|
-
|