oso-cloud 1.9.0 → 1.9.1.pre.vendored.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/.gitignore +0 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +31 -12
- data/lib/oso/api.rb +18 -2
- data/lib/oso/version.rb +1 -1
- data/vendor/gems/faraday-2.5.2/CHANGELOG.md +574 -0
- data/vendor/gems/faraday-2.5.2/LICENSE.md +20 -0
- data/vendor/gems/faraday-2.5.2/README.md +55 -0
- data/vendor/gems/faraday-2.5.2/Rakefile +7 -0
- data/vendor/gems/faraday-2.5.2/examples/client_spec.rb +119 -0
- data/vendor/gems/faraday-2.5.2/examples/client_test.rb +144 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter/test.rb +298 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter.rb +102 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter_registry.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/connection.rb +561 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/error.rb +147 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/logging/formatter.rb +106 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/methods.rb +6 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware_registry.rb +83 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/connection_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/env.rb +199 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/proxy_options.rb +32 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/request_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/ssl_options.rb +69 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options.rb +218 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/parameters.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/rack_builder.rb +252 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/authorization.rb +49 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/instrumentation.rb +56 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/json.rb +55 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/url_encoded.rb +60 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request.rb +136 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/json.rb +54 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/logger.rb +33 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/raise_error.rb +64 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response.rb +90 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/headers.rb +139 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/params_hash.rb +61 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils.rb +122 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/version.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday.rb +157 -0
- data/vendor/gems/faraday-2.5.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter/test_spec.rb +413 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_registry_spec.rb +28 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_spec.rb +55 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/connection_spec.rb +793 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/error_spec.rb +60 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_registry_spec.rb +31 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_spec.rb +52 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/env_spec.rb +76 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/options_spec.rb +297 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/request_options_spec.rb +19 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/nested_spec.rb +150 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/rack_builder_spec.rb +317 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/authorization_spec.rb +83 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/instrumentation_spec.rb +74 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/json_spec.rb +111 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/url_encoded_spec.rb +93 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request_spec.rb +110 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/json_spec.rb +117 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/logger_spec.rb +220 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/raise_error_spec.rb +172 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response_spec.rb +75 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils/headers_spec.rb +82 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils_spec.rb +118 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday_spec.rb +37 -0
- data/vendor/gems/faraday-2.5.2/spec/spec_helper.rb +132 -0
- data/vendor/gems/faraday-2.5.2/spec/support/disabling_stub.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/support/fake_safe_buffer.rb +15 -0
- data/vendor/gems/faraday-2.5.2/spec/support/helper_methods.rb +96 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/adapter.rb +105 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/params_encoder.rb +18 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/request_method.rb +263 -0
- data/vendor/gems/faraday-2.5.2/spec/support/streaming_response_checker.rb +35 -0
- data/vendor/gems/faraday-net_http-3.0.2/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http-3.0.2/README.md +57 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/adapter/net_http.rb +208 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http/version.rb +7 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http.rb +10 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/README.md +66 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/adapter/net_http_persistent.rb +234 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent/version.rb +7 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent.rb +18 -0
- data/vendor/gems/faraday-retry-2.0.0/CHANGELOG.md +24 -0
- data/vendor/gems/faraday-retry-2.0.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-retry-2.0.0/README.md +169 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retriable_response.rb +8 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/middleware.rb +254 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/version.rb +7 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry.rb +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/.autotest +9 -0
- data/vendor/gems/net-http-persistent-4.0.5/.gemtest +0 -0
- data/vendor/gems/net-http-persistent-4.0.5/Gemfile +14 -0
- data/vendor/gems/net-http-persistent-4.0.5/History.txt +460 -0
- data/vendor/gems/net-http-persistent-4.0.5/Manifest.txt +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/README.rdoc +82 -0
- data/vendor/gems/net-http-persistent-4.0.5/Rakefile +25 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/connection.rb +41 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/pool.rb +65 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/timed_stack_multi.rb +79 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent.rb +1158 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent.rb +1512 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
- metadata +108 -4
@@ -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,105 @@
|
|
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.fetch('SSL_FILE', nil)
|
41
|
+
conn_options[:ssl][:verify_hostname] ||= ENV['SSL_VERIFY_HOSTNAME'] == 'yes'
|
42
|
+
|
43
|
+
Faraday.new(remote, conn_options) do |conn|
|
44
|
+
conn.request :url_encoded
|
45
|
+
conn.response :raise_error
|
46
|
+
conn.adapter described_class, *adapter_options
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
let!(:request_stub) { stub_request(http_method, stub_remote) }
|
51
|
+
|
52
|
+
after do
|
53
|
+
expect(request_stub).to have_been_requested unless request_stub.disabled?
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#delete' do
|
57
|
+
let(:http_method) { :delete }
|
58
|
+
|
59
|
+
it_behaves_like 'a request method', :delete
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#get' do
|
63
|
+
let(:http_method) { :get }
|
64
|
+
|
65
|
+
it_behaves_like 'a request method', :get
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#head' do
|
69
|
+
let(:http_method) { :head }
|
70
|
+
|
71
|
+
it_behaves_like 'a request method', :head
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#options' do
|
75
|
+
let(:http_method) { :options }
|
76
|
+
|
77
|
+
it_behaves_like 'a request method', :options
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#patch' do
|
81
|
+
let(:http_method) { :patch }
|
82
|
+
|
83
|
+
it_behaves_like 'a request method', :patch
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#post' do
|
87
|
+
let(:http_method) { :post }
|
88
|
+
|
89
|
+
it_behaves_like 'a request method', :post
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#put' do
|
93
|
+
let(:http_method) { :put }
|
94
|
+
|
95
|
+
it_behaves_like 'a request method', :put
|
96
|
+
end
|
97
|
+
|
98
|
+
on_feature :trace_method do
|
99
|
+
describe '#trace' do
|
100
|
+
let(:http_method) { :trace }
|
101
|
+
|
102
|
+
it_behaves_like 'a request method', :trace
|
103
|
+
end
|
104
|
+
end
|
105
|
+
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,263 @@
|
|
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 'handles streaming' do
|
157
|
+
env = nil
|
158
|
+
conn.public_send(http_method, '/') do |req|
|
159
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
160
|
+
streamed << [chunk, size]
|
161
|
+
env ||= block_env
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
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)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when response contains big data' do
|
173
|
+
before { request_stub.to_return(body: big_string) }
|
174
|
+
|
175
|
+
it 'handles streaming' do
|
176
|
+
env = nil
|
177
|
+
response = conn.public_send(http_method, '/') do |req|
|
178
|
+
req.options.on_data = proc do |chunk, size, block_env|
|
179
|
+
streamed << [chunk, size]
|
180
|
+
env ||= block_env
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
expect(response.body).to eq('')
|
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)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
on_feature :parallel do
|
195
|
+
context 'with parallel setup' do
|
196
|
+
before do
|
197
|
+
@resp1 = nil
|
198
|
+
@resp2 = nil
|
199
|
+
@payload1 = { a: '1' }
|
200
|
+
@payload2 = { b: '2' }
|
201
|
+
|
202
|
+
request_stub
|
203
|
+
.with({ query_or_body => @payload1 })
|
204
|
+
.to_return(body: @payload1.to_json)
|
205
|
+
|
206
|
+
stub_request(http_method, remote)
|
207
|
+
.with({ query_or_body => @payload2 })
|
208
|
+
.to_return(body: @payload2.to_json)
|
209
|
+
|
210
|
+
conn.in_parallel do
|
211
|
+
@resp1 = conn.public_send(http_method, '/', @payload1)
|
212
|
+
@resp2 = conn.public_send(http_method, '/', @payload2)
|
213
|
+
|
214
|
+
expect(conn.in_parallel?).to be_truthy
|
215
|
+
expect(@resp1.body).to be_nil
|
216
|
+
expect(@resp2.body).to be_nil
|
217
|
+
end
|
218
|
+
|
219
|
+
expect(conn.in_parallel?).to be_falsey
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'handles parallel requests status' do
|
223
|
+
expect(@resp1&.status).to eq(200)
|
224
|
+
expect(@resp2&.status).to eq(200)
|
225
|
+
end
|
226
|
+
|
227
|
+
unless http_method == :head && feature?(:skip_response_body_on_head)
|
228
|
+
it 'handles parallel requests body' do
|
229
|
+
expect(@resp1&.body).to eq(@payload1.to_json)
|
230
|
+
expect(@resp2&.body).to eq(@payload2.to_json)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'when a proxy is provided as option' do
|
237
|
+
before do
|
238
|
+
conn_options[:proxy] = 'http://env-proxy.com:80'
|
239
|
+
end
|
240
|
+
|
241
|
+
include_examples 'proxy examples'
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'when http_proxy env variable is set' do
|
245
|
+
let(:proxy_url) { 'http://env-proxy.com:80' }
|
246
|
+
|
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
|
262
|
+
end
|
263
|
+
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,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jan van der Pas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Faraday Net::HTTP adapter
|
2
|
+
|
3
|
+
This gem is a [Faraday][faraday] adapter for the [Net::HTTP][net-http] library. Faraday is an HTTP client library that provides a common interface over many adapters. Every adapter is defined into it's own gem. This gem defines the adapter for `Net::HTTP` the HTTP library that's included into the standard library of Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'faraday-net_http'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install faraday-net_http
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
conn = Faraday.new(...) do |f|
|
25
|
+
f.adapter :net_http do |http|
|
26
|
+
# yields Net::HTTP
|
27
|
+
http.verify_callback = lambda do |preverify, cert_store|
|
28
|
+
# do something here...
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](rubygems).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on [GitHub][repo].
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [license][license].
|
47
|
+
|
48
|
+
## Code of Conduct
|
49
|
+
|
50
|
+
Everyone interacting in the Faraday Net::HTTP adapter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
|
51
|
+
|
52
|
+
[faraday]: https://github.com/lostisland/faraday
|
53
|
+
[net-http]: https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html
|
54
|
+
[rubygems]: https://rubygems.org
|
55
|
+
[repo]: https://github.com/lostisland/faraday-net_http
|
56
|
+
[license]: https://github.com/lostisland/faraday-net_http/blob/main/LICENSE.md
|
57
|
+
[code-of-conduct]: https://github.com/lostisland/faraday-net_http/blob/main/CODE_OF_CONDUCT.md
|