faraday-net_http 3.4.4 → 3.5.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/README.md +35 -1
- data/lib/faraday/adapter/net_http.rb +37 -5
- data/lib/faraday/net_http/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 658606c949eb5a714696b89cf5c75cace8c212e9b2df7688ecc5d1bb5ab6442c
|
|
4
|
+
data.tar.gz: 7f52a4ae649cfd20426dc480511ed77c8fa0a2ad8d52e76d9c851516d356d1e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f8aa0043df43b4562a9aa1e2d519e2a3a34e93ca30a293f0a84448c123c518c02bafe21ac79bb0f82d7a41e6e76fd53636f1d5b5db1ef53692001d9bcc658a2
|
|
7
|
+
data.tar.gz: accb8c3da7c1dcf7ebc22d53495d7f438cd1aea2ca625f2d8d5ec22401ddda66e7a013b2bfeffcb3003374f79c18d1c0276be72f117ebb60b57ab8117bfc7d6c
|
data/README.md
CHANGED
|
@@ -31,11 +31,44 @@ conn = Faraday.new(...) do |f|
|
|
|
31
31
|
end
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
### Restricting trusted certificate authorities
|
|
35
|
+
|
|
36
|
+
By default, `ca_file` and `ca_path` add certificate authorities to the system
|
|
37
|
+
trust store. They do not restrict trust to only the supplied authorities.
|
|
38
|
+
To restrict trust, provide an explicit certificate store. An empty store lets
|
|
39
|
+
you trust only the authorities supplied through `ca_file` or `ca_path`:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
require 'openssl'
|
|
43
|
+
|
|
44
|
+
conn = Faraday.new('https://example.com', ssl: {
|
|
45
|
+
ca_file: '/path/to/trusted-ca.pem',
|
|
46
|
+
cert_store: OpenSSL::X509::Store.new
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Certificate and hostname verification remain enabled. Alternatively, populate
|
|
51
|
+
the explicit store yourself with `add_file` or `add_cert` and omit `ca_file`.
|
|
52
|
+
|
|
53
|
+
### SOCKS proxy
|
|
54
|
+
|
|
55
|
+
A `socks://` proxy is supported when the optional [socksify][socksify] gem (`~> 1.8`) is installed. It is not a dependency of this gem, so add it to your Gemfile:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
gem 'socksify', '~> 1.8'
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
conn = Faraday.new(url, proxy: 'socks://user:password@127.0.0.1:1080')
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Using a `socks://` proxy without socksify raises a `RuntimeError`.
|
|
66
|
+
|
|
34
67
|
## Development
|
|
35
68
|
|
|
36
69
|
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
70
|
|
|
38
|
-
To release a new version, update the version number in `version.rb`,
|
|
71
|
+
To release a new version, update the version number in `version.rb`, then commit and push that to `main` branch. Then, use GitHub Releases to create a matching Release. A GitHub Action will publish the gem to Rubygems.org.
|
|
39
72
|
|
|
40
73
|
## Contributing
|
|
41
74
|
|
|
@@ -51,6 +84,7 @@ Everyone interacting in the Faraday Net::HTTP adapter project's codebases, issue
|
|
|
51
84
|
|
|
52
85
|
[faraday]: https://github.com/lostisland/faraday
|
|
53
86
|
[net-http]: https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html
|
|
87
|
+
[socksify]: https://github.com/astro/socksify-ruby
|
|
54
88
|
[rubygems]: https://rubygems.org
|
|
55
89
|
[repo]: https://github.com/lostisland/faraday-net_http
|
|
56
90
|
[license]: https://github.com/lostisland/faraday-net_http/blob/main/LICENSE.md
|
|
@@ -7,6 +7,13 @@ rescue LoadError
|
|
|
7
7
|
'Make sure openssl is installed if you want ssl support'
|
|
8
8
|
require 'net/http'
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
begin
|
|
12
|
+
require 'socksify/http'
|
|
13
|
+
rescue LoadError
|
|
14
|
+
# socksify is optional and only required when using a SOCKS proxy
|
|
15
|
+
end
|
|
16
|
+
|
|
10
17
|
require 'zlib'
|
|
11
18
|
|
|
12
19
|
module Faraday
|
|
@@ -27,16 +34,21 @@ module Faraday
|
|
|
27
34
|
Net::HTTPHeaderSyntaxError,
|
|
28
35
|
Net::ProtocolError,
|
|
29
36
|
SocketError,
|
|
30
|
-
Zlib::GzipFile::Error
|
|
37
|
+
Zlib::GzipFile::Error,
|
|
38
|
+
Zlib::DataError,
|
|
39
|
+
Zlib::NeedDict,
|
|
40
|
+
Zlib::BufError
|
|
31
41
|
]
|
|
32
42
|
|
|
33
43
|
exceptions << ::OpenSSL::SSL::SSLError if defined?(::OpenSSL::SSL::SSLError)
|
|
34
44
|
exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
|
|
45
|
+
exceptions << ::SOCKSError if defined?(::SOCKSError)
|
|
35
46
|
|
|
36
47
|
NET_HTTP_EXCEPTIONS = exceptions.freeze
|
|
37
48
|
|
|
38
49
|
def initialize(app = nil, opts = {}, &block)
|
|
39
50
|
@ssl_cert_store = nil
|
|
51
|
+
@ssl_cert_store_mutex = Mutex.new
|
|
40
52
|
super(app, opts, &block)
|
|
41
53
|
end
|
|
42
54
|
|
|
@@ -50,7 +62,9 @@ module Faraday
|
|
|
50
62
|
def net_http_connection(env)
|
|
51
63
|
proxy = env[:request][:proxy]
|
|
52
64
|
port = env[:url].port || (env[:url].scheme == 'https' ? 443 : 80)
|
|
53
|
-
if proxy
|
|
65
|
+
if socks_proxy?(proxy)
|
|
66
|
+
socks_proxy_class(proxy).new(env[:url].hostname, port, nil)
|
|
67
|
+
elsif proxy
|
|
54
68
|
Net::HTTP.new(env[:url].hostname, port,
|
|
55
69
|
proxy[:uri].hostname, proxy[:uri].port,
|
|
56
70
|
proxy[:user], proxy[:password],
|
|
@@ -128,6 +142,20 @@ module Faraday
|
|
|
128
142
|
end
|
|
129
143
|
end
|
|
130
144
|
|
|
145
|
+
def socks_proxy?(proxy)
|
|
146
|
+
proxy && proxy[:uri].scheme == 'socks'
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def socks_proxy_class(proxy)
|
|
150
|
+
raise 'SOCKS proxy support requires the socksify gem ~> 1.8' unless Net::HTTP.respond_to?(:socks_proxy)
|
|
151
|
+
|
|
152
|
+
# socksify stores its settings on a class shared by every
|
|
153
|
+
# Net::HTTP.socks_proxy call, so use a subclass to keep proxies isolated.
|
|
154
|
+
Class.new(Net::HTTP).socks_proxy(proxy[:uri].hostname, proxy[:uri].port,
|
|
155
|
+
username: proxy[:user],
|
|
156
|
+
password: proxy[:password])
|
|
157
|
+
end
|
|
158
|
+
|
|
131
159
|
def configure_ssl(http, ssl)
|
|
132
160
|
http.use_ssl = true if http.respond_to?(:use_ssl=)
|
|
133
161
|
|
|
@@ -173,7 +201,9 @@ module Faraday
|
|
|
173
201
|
return ssl[:cert_store] if ssl[:cert_store]
|
|
174
202
|
|
|
175
203
|
# Use the default cert store by default, i.e. system ca certs
|
|
176
|
-
@ssl_cert_store ||=
|
|
204
|
+
@ssl_cert_store ||= @ssl_cert_store_mutex.synchronize do
|
|
205
|
+
@ssl_cert_store ||= OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
|
206
|
+
end
|
|
177
207
|
end
|
|
178
208
|
|
|
179
209
|
def ssl_verify_mode(ssl)
|
|
@@ -188,8 +218,10 @@ module Faraday
|
|
|
188
218
|
|
|
189
219
|
def encoded_body(http_response)
|
|
190
220
|
body = http_response.body || +''
|
|
191
|
-
|
|
192
|
-
|
|
221
|
+
/(?:\A|;)\s*charset=([^;]+)/i.match(http_response['Content-Type']) do |match|
|
|
222
|
+
charset = match[1].strip
|
|
223
|
+
charset = charset[1...-1] if charset.start_with?('"') && charset.end_with?('"')
|
|
224
|
+
content_charset = ::Encoding.find(charset)
|
|
193
225
|
body = body.dup.force_encoding(content_charset)
|
|
194
226
|
rescue ArgumentError
|
|
195
227
|
nil
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faraday-net_http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan van der Pas
|
|
@@ -41,7 +41,7 @@ licenses:
|
|
|
41
41
|
metadata:
|
|
42
42
|
homepage_uri: https://github.com/lostisland/faraday-net_http
|
|
43
43
|
source_code_uri: https://github.com/lostisland/faraday-net_http
|
|
44
|
-
changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.
|
|
44
|
+
changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.5.0
|
|
45
45
|
rubygems_mfa_required: 'true'
|
|
46
46
|
rdoc_options: []
|
|
47
47
|
require_paths:
|
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
57
57
|
- !ruby/object:Gem::Version
|
|
58
58
|
version: '0'
|
|
59
59
|
requirements: []
|
|
60
|
-
rubygems_version:
|
|
60
|
+
rubygems_version: 4.0.20
|
|
61
61
|
specification_version: 4
|
|
62
62
|
summary: Faraday adapter for Net::HTTP
|
|
63
63
|
test_files: []
|