faraday-net_http 1.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/lib/faraday/adapter/net_http.rb +46 -51
- data/lib/faraday/net_http/version.rb +1 -1
- data/lib/faraday/net_http.rb +2 -2
- metadata +9 -135
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cad2197cf7df07a668741fb5ae27309b6f7aee396b207268ba63076569ae59f
|
4
|
+
data.tar.gz: 47fbe72a4c70f85b5659376f0a758088d26c8a6f2901a8320a22bfba872e2c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b6cb45789018beedcef079c136c213e6532aba87d2503bd6f1544cf30f3ab3cdda9c08e4164d0f93a056595622cdf9c8f125e19798f8147e3e52f1387c5c800
|
7
|
+
data.tar.gz: 66131665eb559ad8b1bbba18c12916c3ace677b93a6055269c7def945dced9021f2864df22d9326880a8379602e0ac78fd44f49c137217e05978fa7377cedb3d
|
data/README.md
CHANGED
@@ -20,16 +20,17 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Configure your Faraday connection to use this adapter like this:
|
24
|
-
|
25
23
|
```ruby
|
26
|
-
|
27
|
-
|
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
|
28
31
|
end
|
29
32
|
```
|
30
33
|
|
31
|
-
For more information on how to setup your Faraday connection and adapters usage, please refer to the [Faraday Website][faraday-website].
|
32
|
-
|
33
34
|
## Development
|
34
35
|
|
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.
|
@@ -49,9 +50,8 @@ The gem is available as open source under the terms of the [license][license].
|
|
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].
|
50
51
|
|
51
52
|
[faraday]: https://github.com/lostisland/faraday
|
52
|
-
[faraday-website]: https://lostisland.github.io/faraday
|
53
53
|
[net-http]: https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html
|
54
54
|
[rubygems]: https://rubygems.org
|
55
55
|
[repo]: https://github.com/lostisland/faraday-net_http
|
56
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
|
57
|
+
[code-of-conduct]: https://github.com/lostisland/faraday-net_http/blob/main/CODE_OF_CONDUCT.md
|
@@ -15,6 +15,7 @@ module Faraday
|
|
15
15
|
exceptions = [
|
16
16
|
IOError,
|
17
17
|
Errno::EADDRNOTAVAIL,
|
18
|
+
Errno::EALREADY,
|
18
19
|
Errno::ECONNABORTED,
|
19
20
|
Errno::ECONNREFUSED,
|
20
21
|
Errno::ECONNRESET,
|
@@ -61,24 +62,13 @@ module Faraday
|
|
61
62
|
|
62
63
|
def call(env)
|
63
64
|
super
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
|
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
69
|
|
70
|
-
|
71
|
-
end
|
70
|
+
raise Faraday::ConnectionFailed, e
|
72
71
|
end
|
73
|
-
|
74
|
-
save_response(env, http_response.code.to_i,
|
75
|
-
http_response.body || +'', nil,
|
76
|
-
http_response.message) do |response_headers|
|
77
|
-
http_response.each_header do |key, value|
|
78
|
-
response_headers[key] = value
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
72
|
@app.call env
|
83
73
|
rescue Timeout::Error, Errno::ETIMEDOUT => e
|
84
74
|
raise Faraday::TimeoutError, e
|
@@ -103,53 +93,41 @@ module Faraday
|
|
103
93
|
end
|
104
94
|
|
105
95
|
def perform_request(http, env)
|
106
|
-
if env
|
107
|
-
|
108
|
-
|
109
|
-
http_response = request_with_wrapped_block(http, env) do |chunk|
|
110
|
-
if chunk.bytesize.positive? || size.positive?
|
111
|
-
yielded = true
|
112
|
-
size += chunk.bytesize
|
113
|
-
env[:request].on_data.call(chunk, size)
|
114
|
-
end
|
96
|
+
if env.stream_response?
|
97
|
+
http_response = env.stream_response do |&on_data|
|
98
|
+
request_with_wrapped_block(http, env, &on_data)
|
115
99
|
end
|
116
|
-
env[:request].on_data.call(+'', 0) unless yielded
|
117
|
-
# Net::HTTP returns something,
|
118
|
-
# but it's not meaningful according to the docs.
|
119
100
|
http_response.body = nil
|
120
|
-
http_response
|
121
|
-
else
|
122
|
-
request_with_wrapped_block(http, env)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def request_with_wrapped_block(http, env, &block)
|
127
|
-
if (env[:method] == :get) && !env[:body]
|
128
|
-
# prefer `get` to `request` because the former handles gzip (ruby 1.9)
|
129
|
-
request_via_get_method(http, env, &block)
|
130
101
|
else
|
131
|
-
|
102
|
+
http_response = request_with_wrapped_block(http, env)
|
132
103
|
end
|
104
|
+
env.response_body = encoded_body(http_response)
|
105
|
+
env.response.finish(env)
|
106
|
+
http_response
|
133
107
|
end
|
134
108
|
|
135
|
-
def
|
109
|
+
def request_with_wrapped_block(http, env)
|
136
110
|
# Must use Net::HTTP#start and pass it a block otherwise the server's
|
137
111
|
# TCP socket does not close correctly.
|
138
112
|
http.start do |opened_http|
|
139
|
-
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
|
140
122
|
end
|
141
123
|
end
|
142
124
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
response.read_body(&block)
|
150
|
-
end
|
151
|
-
else
|
152
|
-
opened_http.request create_request(env)
|
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
|
153
131
|
end
|
154
132
|
end
|
155
133
|
end
|
@@ -168,6 +146,7 @@ module Faraday
|
|
168
146
|
http.ssl_version = ssl[:version] if ssl[:version]
|
169
147
|
http.min_version = ssl[:min_version] if ssl[:min_version]
|
170
148
|
http.max_version = ssl[:max_version] if ssl[:max_version]
|
149
|
+
http.verify_hostname = ssl[:verify_hostname] if verify_hostname_enabled?(http, ssl)
|
171
150
|
end
|
172
151
|
|
173
152
|
def configure_request(http, req)
|
@@ -208,6 +187,22 @@ module Faraday
|
|
208
187
|
end
|
209
188
|
end
|
210
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
|
211
206
|
end
|
212
207
|
end
|
213
208
|
end
|
data/lib/faraday/net_http.rb
CHANGED
metadata
CHANGED
@@ -1,155 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-net_http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan van der Pas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '13.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '13.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.19.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.19.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: multipart-parser
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.1.1
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.1.1
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: webmock
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.4'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.4'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rubocop
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.91.1
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.91.1
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop-packaging
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.5'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.5'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop-performance
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '1.0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '1.0'
|
26
|
+
version: '2.5'
|
153
27
|
description: Faraday adapter for Net::HTTP
|
154
28
|
email:
|
155
29
|
- janvanderpas@gmail.com
|
@@ -168,7 +42,7 @@ licenses:
|
|
168
42
|
metadata:
|
169
43
|
homepage_uri: https://github.com/lostisland/faraday-net_http
|
170
44
|
source_code_uri: https://github.com/lostisland/faraday-net_http
|
171
|
-
changelog_uri: https://github.com/lostisland/faraday-net_http
|
45
|
+
changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.0.2
|
172
46
|
post_install_message:
|
173
47
|
rdoc_options: []
|
174
48
|
require_paths:
|
@@ -177,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
51
|
requirements:
|
178
52
|
- - ">="
|
179
53
|
- !ruby/object:Gem::Version
|
180
|
-
version: 2.
|
54
|
+
version: 2.6.0
|
181
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
56
|
requirements:
|
183
57
|
- - ">="
|
184
58
|
- !ruby/object:Gem::Version
|
185
59
|
version: '0'
|
186
60
|
requirements: []
|
187
|
-
rubygems_version: 3.1.
|
61
|
+
rubygems_version: 3.1.6
|
188
62
|
signing_key:
|
189
63
|
specification_version: 4
|
190
64
|
summary: Faraday adapter for Net::HTTP
|