oso-cloud 1.8.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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +31 -12
  5. data/README.md +1 -1
  6. data/lib/oso/api.rb +18 -2
  7. data/lib/oso/oso.rb +10 -7
  8. data/lib/oso/version.rb +1 -1
  9. data/vendor/gems/faraday-2.5.2/CHANGELOG.md +574 -0
  10. data/vendor/gems/faraday-2.5.2/LICENSE.md +20 -0
  11. data/vendor/gems/faraday-2.5.2/README.md +55 -0
  12. data/vendor/gems/faraday-2.5.2/Rakefile +7 -0
  13. data/vendor/gems/faraday-2.5.2/examples/client_spec.rb +119 -0
  14. data/vendor/gems/faraday-2.5.2/examples/client_test.rb +144 -0
  15. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter/test.rb +298 -0
  16. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter.rb +102 -0
  17. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter_registry.rb +30 -0
  18. data/vendor/gems/faraday-2.5.2/lib/faraday/connection.rb +561 -0
  19. data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  20. data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
  21. data/vendor/gems/faraday-2.5.2/lib/faraday/error.rb +147 -0
  22. data/vendor/gems/faraday-2.5.2/lib/faraday/logging/formatter.rb +106 -0
  23. data/vendor/gems/faraday-2.5.2/lib/faraday/methods.rb +6 -0
  24. data/vendor/gems/faraday-2.5.2/lib/faraday/middleware.rb +30 -0
  25. data/vendor/gems/faraday-2.5.2/lib/faraday/middleware_registry.rb +83 -0
  26. data/vendor/gems/faraday-2.5.2/lib/faraday/options/connection_options.rb +22 -0
  27. data/vendor/gems/faraday-2.5.2/lib/faraday/options/env.rb +199 -0
  28. data/vendor/gems/faraday-2.5.2/lib/faraday/options/proxy_options.rb +32 -0
  29. data/vendor/gems/faraday-2.5.2/lib/faraday/options/request_options.rb +22 -0
  30. data/vendor/gems/faraday-2.5.2/lib/faraday/options/ssl_options.rb +69 -0
  31. data/vendor/gems/faraday-2.5.2/lib/faraday/options.rb +218 -0
  32. data/vendor/gems/faraday-2.5.2/lib/faraday/parameters.rb +5 -0
  33. data/vendor/gems/faraday-2.5.2/lib/faraday/rack_builder.rb +252 -0
  34. data/vendor/gems/faraday-2.5.2/lib/faraday/request/authorization.rb +49 -0
  35. data/vendor/gems/faraday-2.5.2/lib/faraday/request/instrumentation.rb +56 -0
  36. data/vendor/gems/faraday-2.5.2/lib/faraday/request/json.rb +55 -0
  37. data/vendor/gems/faraday-2.5.2/lib/faraday/request/url_encoded.rb +60 -0
  38. data/vendor/gems/faraday-2.5.2/lib/faraday/request.rb +136 -0
  39. data/vendor/gems/faraday-2.5.2/lib/faraday/response/json.rb +54 -0
  40. data/vendor/gems/faraday-2.5.2/lib/faraday/response/logger.rb +33 -0
  41. data/vendor/gems/faraday-2.5.2/lib/faraday/response/raise_error.rb +64 -0
  42. data/vendor/gems/faraday-2.5.2/lib/faraday/response.rb +90 -0
  43. data/vendor/gems/faraday-2.5.2/lib/faraday/utils/headers.rb +139 -0
  44. data/vendor/gems/faraday-2.5.2/lib/faraday/utils/params_hash.rb +61 -0
  45. data/vendor/gems/faraday-2.5.2/lib/faraday/utils.rb +122 -0
  46. data/vendor/gems/faraday-2.5.2/lib/faraday/version.rb +5 -0
  47. data/vendor/gems/faraday-2.5.2/lib/faraday.rb +157 -0
  48. data/vendor/gems/faraday-2.5.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
  49. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter/test_spec.rb +413 -0
  50. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_registry_spec.rb +28 -0
  51. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_spec.rb +55 -0
  52. data/vendor/gems/faraday-2.5.2/spec/faraday/connection_spec.rb +793 -0
  53. data/vendor/gems/faraday-2.5.2/spec/faraday/error_spec.rb +60 -0
  54. data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_registry_spec.rb +31 -0
  55. data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_spec.rb +52 -0
  56. data/vendor/gems/faraday-2.5.2/spec/faraday/options/env_spec.rb +76 -0
  57. data/vendor/gems/faraday-2.5.2/spec/faraday/options/options_spec.rb +297 -0
  58. data/vendor/gems/faraday-2.5.2/spec/faraday/options/proxy_options_spec.rb +44 -0
  59. data/vendor/gems/faraday-2.5.2/spec/faraday/options/request_options_spec.rb +19 -0
  60. data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
  61. data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/nested_spec.rb +150 -0
  62. data/vendor/gems/faraday-2.5.2/spec/faraday/rack_builder_spec.rb +317 -0
  63. data/vendor/gems/faraday-2.5.2/spec/faraday/request/authorization_spec.rb +83 -0
  64. data/vendor/gems/faraday-2.5.2/spec/faraday/request/instrumentation_spec.rb +74 -0
  65. data/vendor/gems/faraday-2.5.2/spec/faraday/request/json_spec.rb +111 -0
  66. data/vendor/gems/faraday-2.5.2/spec/faraday/request/url_encoded_spec.rb +93 -0
  67. data/vendor/gems/faraday-2.5.2/spec/faraday/request_spec.rb +110 -0
  68. data/vendor/gems/faraday-2.5.2/spec/faraday/response/json_spec.rb +117 -0
  69. data/vendor/gems/faraday-2.5.2/spec/faraday/response/logger_spec.rb +220 -0
  70. data/vendor/gems/faraday-2.5.2/spec/faraday/response/raise_error_spec.rb +172 -0
  71. data/vendor/gems/faraday-2.5.2/spec/faraday/response_spec.rb +75 -0
  72. data/vendor/gems/faraday-2.5.2/spec/faraday/utils/headers_spec.rb +82 -0
  73. data/vendor/gems/faraday-2.5.2/spec/faraday/utils_spec.rb +118 -0
  74. data/vendor/gems/faraday-2.5.2/spec/faraday_spec.rb +37 -0
  75. data/vendor/gems/faraday-2.5.2/spec/spec_helper.rb +132 -0
  76. data/vendor/gems/faraday-2.5.2/spec/support/disabling_stub.rb +14 -0
  77. data/vendor/gems/faraday-2.5.2/spec/support/fake_safe_buffer.rb +15 -0
  78. data/vendor/gems/faraday-2.5.2/spec/support/helper_methods.rb +96 -0
  79. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/adapter.rb +105 -0
  80. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/params_encoder.rb +18 -0
  81. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/request_method.rb +263 -0
  82. data/vendor/gems/faraday-2.5.2/spec/support/streaming_response_checker.rb +35 -0
  83. data/vendor/gems/faraday-net_http-3.0.2/LICENSE.md +21 -0
  84. data/vendor/gems/faraday-net_http-3.0.2/README.md +57 -0
  85. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/adapter/net_http.rb +208 -0
  86. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http/version.rb +7 -0
  87. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http.rb +10 -0
  88. data/vendor/gems/faraday-net_http_persistent-2.3.0/LICENSE.md +21 -0
  89. data/vendor/gems/faraday-net_http_persistent-2.3.0/README.md +66 -0
  90. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/adapter/net_http_persistent.rb +234 -0
  91. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent/version.rb +7 -0
  92. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent.rb +18 -0
  93. data/vendor/gems/faraday-retry-2.0.0/CHANGELOG.md +24 -0
  94. data/vendor/gems/faraday-retry-2.0.0/LICENSE.md +21 -0
  95. data/vendor/gems/faraday-retry-2.0.0/README.md +169 -0
  96. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retriable_response.rb +8 -0
  97. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/middleware.rb +254 -0
  98. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/version.rb +7 -0
  99. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry.rb +13 -0
  100. data/vendor/gems/net-http-persistent-4.0.5/.autotest +9 -0
  101. data/vendor/gems/net-http-persistent-4.0.5/.gemtest +0 -0
  102. data/vendor/gems/net-http-persistent-4.0.5/Gemfile +14 -0
  103. data/vendor/gems/net-http-persistent-4.0.5/History.txt +460 -0
  104. data/vendor/gems/net-http-persistent-4.0.5/Manifest.txt +13 -0
  105. data/vendor/gems/net-http-persistent-4.0.5/README.rdoc +82 -0
  106. data/vendor/gems/net-http-persistent-4.0.5/Rakefile +25 -0
  107. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/connection.rb +41 -0
  108. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/pool.rb +65 -0
  109. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  110. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent.rb +1158 -0
  111. data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent.rb +1512 -0
  112. data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
  113. metadata +112 -8
@@ -0,0 +1,208 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'net/https'
5
+ rescue LoadError
6
+ warn 'Warning: no such file to load -- net/https. ' \
7
+ 'Make sure openssl is installed if you want ssl support'
8
+ require 'net/http'
9
+ end
10
+ require 'zlib'
11
+
12
+ module Faraday
13
+ class Adapter
14
+ class NetHttp < Faraday::Adapter
15
+ exceptions = [
16
+ IOError,
17
+ Errno::EADDRNOTAVAIL,
18
+ Errno::EALREADY,
19
+ Errno::ECONNABORTED,
20
+ Errno::ECONNREFUSED,
21
+ Errno::ECONNRESET,
22
+ Errno::EHOSTUNREACH,
23
+ Errno::EINVAL,
24
+ Errno::ENETUNREACH,
25
+ Errno::EPIPE,
26
+ Net::HTTPBadResponse,
27
+ Net::HTTPHeaderSyntaxError,
28
+ Net::ProtocolError,
29
+ SocketError,
30
+ Zlib::GzipFile::Error
31
+ ]
32
+
33
+ exceptions << ::OpenSSL::SSL::SSLError if defined?(::OpenSSL::SSL::SSLError)
34
+ exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
35
+
36
+ NET_HTTP_EXCEPTIONS = exceptions.freeze
37
+
38
+ def initialize(app = nil, opts = {}, &block)
39
+ @ssl_cert_store = nil
40
+ super(app, opts, &block)
41
+ end
42
+
43
+ def build_connection(env)
44
+ net_http_connection(env).tap do |http|
45
+ http.use_ssl = env[:url].scheme == 'https' if http.respond_to?(:use_ssl=)
46
+ configure_ssl(http, env[:ssl])
47
+ configure_request(http, env[:request])
48
+ end
49
+ end
50
+
51
+ def net_http_connection(env)
52
+ proxy = env[:request][:proxy]
53
+ port = env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)
54
+ if proxy
55
+ Net::HTTP.new(env[:url].hostname, port,
56
+ proxy[:uri].hostname, proxy[:uri].port,
57
+ proxy[:user], proxy[:password])
58
+ else
59
+ Net::HTTP.new(env[:url].hostname, port, nil)
60
+ end
61
+ end
62
+
63
+ def call(env)
64
+ super
65
+ connection(env) do |http|
66
+ perform_request(http, env)
67
+ rescue *NET_HTTP_EXCEPTIONS => e
68
+ raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
69
+
70
+ raise Faraday::ConnectionFailed, e
71
+ end
72
+ @app.call env
73
+ rescue Timeout::Error, Errno::ETIMEDOUT => e
74
+ raise Faraday::TimeoutError, e
75
+ end
76
+
77
+ private
78
+
79
+ def create_request(env)
80
+ request = Net::HTTPGenericRequest.new \
81
+ env[:method].to_s.upcase, # request method
82
+ !!env[:body], # is there request body
83
+ env[:method] != :head, # is there response body
84
+ env[:url].request_uri, # request uri path
85
+ env[:request_headers] # request headers
86
+
87
+ if env[:body].respond_to?(:read)
88
+ request.body_stream = env[:body]
89
+ else
90
+ request.body = env[:body]
91
+ end
92
+ request
93
+ end
94
+
95
+ def perform_request(http, env)
96
+ if env.stream_response?
97
+ http_response = env.stream_response do |&on_data|
98
+ request_with_wrapped_block(http, env, &on_data)
99
+ end
100
+ http_response.body = nil
101
+ else
102
+ http_response = request_with_wrapped_block(http, env)
103
+ end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
107
+ end
108
+
109
+ def request_with_wrapped_block(http, env)
110
+ # Must use Net::HTTP#start and pass it a block otherwise the server's
111
+ # TCP socket does not close correctly.
112
+ http.start do |opened_http|
113
+ opened_http.request create_request(env) do |response|
114
+ save_http_response(env, response)
115
+
116
+ if block_given?
117
+ response.read_body do |chunk|
118
+ yield(chunk)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+
125
+ def save_http_response(env, http_response)
126
+ save_response(
127
+ env, http_response.code.to_i, nil, nil, http_response.message, finished: false
128
+ ) do |response_headers|
129
+ http_response.each_header do |key, value|
130
+ response_headers[key] = value
131
+ end
132
+ end
133
+ end
134
+
135
+ def configure_ssl(http, ssl)
136
+ return unless ssl
137
+
138
+ http.verify_mode = ssl_verify_mode(ssl)
139
+ http.cert_store = ssl_cert_store(ssl)
140
+
141
+ http.cert = ssl[:client_cert] if ssl[:client_cert]
142
+ http.key = ssl[:client_key] if ssl[:client_key]
143
+ http.ca_file = ssl[:ca_file] if ssl[:ca_file]
144
+ http.ca_path = ssl[:ca_path] if ssl[:ca_path]
145
+ http.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
146
+ http.ssl_version = ssl[:version] if ssl[:version]
147
+ http.min_version = ssl[:min_version] if ssl[:min_version]
148
+ http.max_version = ssl[:max_version] if ssl[:max_version]
149
+ http.verify_hostname = ssl[:verify_hostname] if verify_hostname_enabled?(http, ssl)
150
+ end
151
+
152
+ def configure_request(http, req)
153
+ if (sec = request_timeout(:read, req))
154
+ http.read_timeout = sec
155
+ end
156
+
157
+ if (sec = http.respond_to?(:write_timeout=) &&
158
+ request_timeout(:write, req))
159
+ http.write_timeout = sec
160
+ end
161
+
162
+ if (sec = request_timeout(:open, req))
163
+ http.open_timeout = sec
164
+ end
165
+
166
+ # Only set if Net::Http supports it, since Ruby 2.5.
167
+ http.max_retries = 0 if http.respond_to?(:max_retries=)
168
+
169
+ @config_block&.call(http)
170
+ end
171
+
172
+ def ssl_cert_store(ssl)
173
+ return ssl[:cert_store] if ssl[:cert_store]
174
+
175
+ @ssl_cert_store ||= begin
176
+ # Use the default cert store by default, i.e. system ca certs
177
+ OpenSSL::X509::Store.new.tap(&:set_default_paths)
178
+ end
179
+ end
180
+
181
+ def ssl_verify_mode(ssl)
182
+ ssl[:verify_mode] || begin
183
+ if ssl.fetch(:verify, true)
184
+ OpenSSL::SSL::VERIFY_PEER
185
+ else
186
+ OpenSSL::SSL::VERIFY_NONE
187
+ end
188
+ end
189
+ end
190
+
191
+ def encoded_body(http_response)
192
+ body = http_response.body || +''
193
+ /\bcharset=([^;]+)/.match(http_response['Content-Type']) do |match|
194
+ content_charset = ::Encoding.find(match[1].strip)
195
+ body = body.dup if body.frozen?
196
+ body.force_encoding(content_charset)
197
+ rescue ArgumentError
198
+ nil
199
+ end
200
+ body
201
+ end
202
+
203
+ def verify_hostname_enabled?(http, ssl)
204
+ http.respond_to?(:verify_hostname=) && ssl.key?(:verify_hostname)
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module NetHttp
5
+ VERSION = '3.0.2'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday/adapter/net_http'
4
+ require 'faraday/net_http/version'
5
+
6
+ module Faraday
7
+ module NetHttp
8
+ Faraday::Adapter.register_middleware(net_http: Faraday::Adapter::NetHttp)
9
+ end
10
+ 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,66 @@
1
+ # Faraday::NetHttpPersistent
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/faraday-net_http_persistent.svg)](https://rubygems.org/gems/faraday-net_http_persistent)
4
+ [![GitHub Actions CI](https://github.com/lostisland/faraday-net_http_persistent/workflows/CI/badge.svg)](https://github.com/lostisland/faraday-net_http_persistent/actions?query=workflow%3ACI)
5
+
6
+ This gem is a [Faraday][faraday] adapter for the [Net::HTTP::Persistent gem][net-http-persistent].
7
+
8
+ ## Installation
9
+
10
+ Add this to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'faraday-net_http_persistent', '~> 2.0'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'faraday/net_http_persistent'
24
+
25
+ conn = Faraday.new(...) do |f|
26
+ f.adapter :net_http_persistent, pool_size: 5 do |http|
27
+ # yields Net::HTTP::Persistent
28
+ http.idle_timeout = 100
29
+ end
30
+ end
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies.
36
+ Then, run `rake spec` to run the tests. You can also run `bin/console`
37
+ for an interactive prompt that will allow you to experiment.
38
+
39
+ To install this gem onto your local machine, run `bundle exec rake install`.
40
+ To release a new version, update the version number in `version.rb`,
41
+ and then run `bundle exec rake release`, which will create a git tag for the version,
42
+ push git commits and tags, and push the `.gem` file to [rubygems.org].
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lostisland/faraday-net_http_persistent.
47
+ This project is intended to be a safe, welcoming space for collaboration,
48
+ and contributors are expected to adhere to the [Contributor Covenant][covenant] code of conduct.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License][mit-license].
53
+
54
+ ## Code of Conduct
55
+
56
+ This project is intended to be a safe, welcoming space for collaboration.
57
+ Everyone interacting in the Faraday::Http project’s codebases, issue trackers,
58
+ chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
59
+
60
+ [code-of-conduct]: https://github.com/lostisland/faraday-http/blob/main/CODE_OF_CONDUCT.md
61
+ [covenant]: http://contributor-covenant.org
62
+ [faraday]: https://github.com/lostisland/faraday
63
+ [faraday-website]: https://lostisland.github.io/faraday
64
+ [net-http-persistent]: https://github.com/drbrain/net-http-persistent
65
+ [mit-license]: https://opensource.org/licenses/MIT
66
+ [rubygems.org]: https://rubygems.org
@@ -0,0 +1,234 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http/persistent"
4
+
5
+ module Faraday
6
+ class Adapter
7
+ # Net::HTTP::Persistent adapter.
8
+ class NetHttpPersistent < Faraday::Adapter
9
+ exceptions = [
10
+ IOError,
11
+ Errno::EADDRNOTAVAIL,
12
+ Errno::EALREADY,
13
+ Errno::ECONNABORTED,
14
+ Errno::ECONNREFUSED,
15
+ Errno::ECONNRESET,
16
+ Errno::EHOSTUNREACH,
17
+ Errno::EINVAL,
18
+ Errno::ENETUNREACH,
19
+ Errno::EPIPE,
20
+ Net::HTTPBadResponse,
21
+ Net::HTTPHeaderSyntaxError,
22
+ Net::ProtocolError,
23
+ SocketError,
24
+ Zlib::GzipFile::Error
25
+ ]
26
+
27
+ exceptions << ::OpenSSL::SSL::SSLError if defined?(::OpenSSL::SSL::SSLError)
28
+ # TODO (breaking): Enable this to make it consistent with net_http adapter.
29
+ # See https://github.com/lostisland/faraday/issues/718#issuecomment-344549382
30
+ # exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
31
+
32
+ NET_HTTP_EXCEPTIONS = exceptions.freeze
33
+
34
+ def initialize(app = nil, opts = {}, &block)
35
+ @ssl_cert_store = nil
36
+ super(app, opts, &block)
37
+ end
38
+
39
+ def call(env)
40
+ super
41
+ connection(env) do |http|
42
+ perform_request(http, env)
43
+ rescue Net::HTTP::Persistent::Error => e
44
+ raise Faraday::TimeoutError, e if e.message.include?("Timeout")
45
+
46
+ raise Faraday::ConnectionFailed, e if e.message.include?("connection refused")
47
+
48
+ raise
49
+ rescue *NET_HTTP_EXCEPTIONS => e
50
+ raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
51
+
52
+ raise Faraday::ConnectionFailed, e
53
+ end
54
+ @app.call env
55
+ rescue Timeout::Error, Errno::ETIMEDOUT => e
56
+ raise Faraday::TimeoutError, e
57
+ end
58
+
59
+ def close
60
+ @cached_connection&.shutdown
61
+ end
62
+
63
+ private
64
+
65
+ def build_connection(env)
66
+ net_http_connection(env).tap do |http|
67
+ http.use_ssl = env[:url].scheme == "https" if http.respond_to?(:use_ssl=)
68
+ configure_ssl(http, env[:ssl])
69
+ configure_request(http, env[:request])
70
+ end
71
+ end
72
+
73
+ def create_request(env)
74
+ request = Net::HTTPGenericRequest.new \
75
+ env[:method].to_s.upcase, # request method
76
+ !!env[:body], # is there request body
77
+ env[:method] != :head, # is there response body
78
+ env[:url].request_uri, # request uri path
79
+ env[:request_headers] # request headers
80
+
81
+ if env[:body].respond_to?(:read)
82
+ request.body_stream = env[:body]
83
+ else
84
+ request.body = env[:body]
85
+ end
86
+ request
87
+ end
88
+
89
+ def save_http_response(env, http_response)
90
+ save_response(
91
+ env, http_response.code.to_i, nil, nil, http_response.message, finished: false
92
+ ) do |response_headers|
93
+ http_response.each_header do |key, value|
94
+ response_headers[key] = value
95
+ end
96
+ end
97
+ end
98
+
99
+ def configure_request(http, req)
100
+ if (sec = request_timeout(:read, req))
101
+ http.read_timeout = sec
102
+ end
103
+
104
+ if (sec = http.respond_to?(:write_timeout=) &&
105
+ request_timeout(:write, req))
106
+ http.write_timeout = sec
107
+ end
108
+
109
+ if (sec = request_timeout(:open, req))
110
+ http.open_timeout = sec
111
+ end
112
+
113
+ # Only set if Net::Http supports it, since Ruby 2.5.
114
+ http.max_retries = 0 if http.respond_to?(:max_retries=)
115
+
116
+ @config_block&.call(http)
117
+ end
118
+
119
+ def ssl_cert_store(ssl)
120
+ return ssl[:cert_store] if ssl[:cert_store]
121
+
122
+ # Use the default cert store by default, i.e. system ca certs
123
+ @ssl_cert_store ||= OpenSSL::X509::Store.new.tap(&:set_default_paths)
124
+ end
125
+
126
+ def net_http_connection(env)
127
+ @cached_connection ||= Net::HTTP::Persistent.new(**init_options)
128
+
129
+ proxy_uri = proxy_uri(env)
130
+ @cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri
131
+ @cached_connection
132
+ end
133
+
134
+ def init_options
135
+ options = {}
136
+ options[:name] = @connection_options.fetch(:name, "Faraday")
137
+ options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
138
+ options
139
+ end
140
+
141
+ def proxy_uri(env)
142
+ proxy_uri = nil
143
+ if (proxy = env[:request][:proxy])
144
+ proxy_uri = if proxy[:uri].is_a?(::URI::HTTP)
145
+ proxy[:uri].dup
146
+ else
147
+ ::URI.parse(proxy[:uri].to_s)
148
+ end
149
+ proxy_uri.user = proxy[:user] if proxy[:user]
150
+ proxy_uri.password = proxy[:password] if proxy[:password]
151
+ end
152
+ proxy_uri
153
+ end
154
+
155
+ def perform_request(http, env)
156
+ if env.stream_response?
157
+ http_response = env.stream_response do |&on_data|
158
+ request_with_wrapped_block(http, env, &on_data)
159
+ end
160
+ http_response.body = nil
161
+ else
162
+ http_response = request_with_wrapped_block(http, env)
163
+ end
164
+ env.response_body = encoded_body(http_response)
165
+ env.response.finish(env)
166
+ http_response
167
+ end
168
+
169
+ def request_with_wrapped_block(http, env)
170
+ http.request(env[:url], create_request(env)) do |response|
171
+ save_http_response(env, response)
172
+
173
+ if block_given?
174
+ response.read_body do |chunk|
175
+ yield(chunk)
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ SSL_CONFIGURATIONS = {
182
+ certificate: :client_cert,
183
+ private_key: :client_key,
184
+ ca_file: :ca_file,
185
+ ssl_version: :version,
186
+ min_version: :min_version,
187
+ max_version: :max_version,
188
+ verify_hostname: :verify_hostname
189
+ }
190
+
191
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new("2.11.0")
192
+ SSL_CONFIGURATIONS[:ciphers] = :ciphers
193
+ end
194
+
195
+ SSL_CONFIGURATIONS.freeze
196
+
197
+ def configure_ssl(http, ssl)
198
+ return unless ssl
199
+
200
+ http_set(http, :verify_mode, ssl_verify_mode(ssl))
201
+ http_set(http, :cert_store, ssl_cert_store(ssl))
202
+
203
+ SSL_CONFIGURATIONS
204
+ .select { |_, key| !ssl[key].nil? }
205
+ .each { |target, key| http_set(http, target, ssl[key]) }
206
+ end
207
+
208
+ def http_set(http, attr, value)
209
+ http.send("#{attr}=", value) if http.send(attr) != value
210
+ end
211
+
212
+ def ssl_verify_mode(ssl)
213
+ ssl[:verify_mode] ||
214
+ if ssl.fetch(:verify, true)
215
+ OpenSSL::SSL::VERIFY_PEER
216
+ else
217
+ OpenSSL::SSL::VERIFY_NONE
218
+ end
219
+ end
220
+
221
+ def encoded_body(http_response)
222
+ body = http_response.body || +""
223
+ /\bcharset=\s*(.+?)\s*(;|$)/.match(http_response["Content-Type"]) do |match|
224
+ content_charset = ::Encoding.find(match.captures.first)
225
+ body = body.dup if body.frozen?
226
+ body.force_encoding(content_charset)
227
+ rescue ArgumentError
228
+ nil
229
+ end
230
+ body
231
+ end
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module NetHttpPersistent
5
+ VERSION = "2.3.0"
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/adapter/net_http_persistent"
5
+ require "faraday/net_http_persistent/version"
6
+
7
+ module Faraday
8
+ module NetHttpPersistent
9
+ # Faraday allows you to register your middleware for easier configuration.
10
+ # This step is totally optional, but it basically allows users to use a custom symbol (in this case, `:net_http_persistent`),
11
+ # to use your adapter in their connections.
12
+ # After calling this line, the following are both valid ways to set the adapter in a connection:
13
+ # * conn.adapter Faraday::Adapter::NetNttpPersistent
14
+ # * conn.adapter :net_http_persistent
15
+ # Without this line, only the former method is valid.
16
+ Faraday::Adapter.register_middleware(net_http_persistent: Faraday::Adapter::NetHttpPersistent)
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ ## v2.0.0 (2022-06-08)
4
+
5
+ ### Changed
6
+
7
+ * `retry_block` now takes keyword arguments instead of positional (backwards incompatible)
8
+ * `retry_block`'s `retry_count` argument now counts up from 0, instead of old `retries_remaining`
9
+
10
+ ### Added
11
+
12
+ * Support for the `RateLimit-Reset` header. [PR #9](https://github.com/lostisland/faraday-retry/pull/9). Thanks, [@maxprokopiev]!
13
+ * `retry_block` has additional `will_retry_in` argument with upcoming delay before retry in seconds.
14
+
15
+ ## v1.0
16
+
17
+ Initial release.
18
+ This release consists of the same middleware that was previously bundled with Faraday but removed in Faraday v2.0, plus:
19
+
20
+ ### Fixed
21
+
22
+ * Retry middleware `retry_block` is not called if retry will not happen due to `max_interval`, https://github.com/lostisland/faraday/pull/1350
23
+
24
+ [@maxprokopiev]: https://github.com/maxprokopiev
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Mattia Giuffrida
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.