http 5.2.0 → 5.3.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/.rubocop/rspec.yml +9 -0
- data/.rubocop_todo.yml +45 -32
- data/CHANGELOG.md +17 -1
- data/Gemfile +1 -0
- data/http.gemspec +7 -2
- data/lib/http/base64.rb +12 -0
- data/lib/http/chainable.rb +27 -3
- data/lib/http/connection.rb +4 -2
- data/lib/http/errors.rb +16 -0
- data/lib/http/feature.rb +2 -1
- data/lib/http/features/raise_error.rb +22 -0
- data/lib/http/headers/normalizer.rb +69 -0
- data/lib/http/headers.rb +26 -40
- data/lib/http/request/writer.rb +2 -1
- data/lib/http/request.rb +3 -2
- data/lib/http/retriable/client.rb +37 -0
- data/lib/http/retriable/delay_calculator.rb +64 -0
- data/lib/http/retriable/errors.rb +14 -0
- data/lib/http/retriable/performer.rb +153 -0
- data/lib/http/version.rb +1 -1
- data/lib/http.rb +1 -0
- data/spec/lib/http/features/raise_error_spec.rb +62 -0
- data/spec/lib/http/headers/normalizer_spec.rb +52 -0
- data/spec/lib/http/redirector_spec.rb +6 -5
- data/spec/lib/http/retriable/delay_calculator_spec.rb +69 -0
- data/spec/lib/http/retriable/performer_spec.rb +302 -0
- data/spec/lib/http_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/dummy_server/servlet.rb +13 -0
- data/spec/support/dummy_server.rb +2 -1
- metadata +21 -19
data/spec/lib/http_spec.rb
CHANGED
@@ -152,6 +152,35 @@ RSpec.describe HTTP do
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
+
describe ".retry" do
|
156
|
+
it "ensure endpoint counts retries" do
|
157
|
+
expect(HTTP.get("#{dummy.endpoint}/retry-2").to_s).to eq "retried 1x"
|
158
|
+
expect(HTTP.get("#{dummy.endpoint}/retry-2").to_s).to eq "retried 2x"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "retries the request" do
|
162
|
+
response = HTTP.retriable(delay: 0, retry_statuses: 500...600).get "#{dummy.endpoint}/retry-2"
|
163
|
+
expect(response.to_s).to eq "retried 2x"
|
164
|
+
end
|
165
|
+
|
166
|
+
it "retries the request and gives us access to the failed requests" do
|
167
|
+
err = nil
|
168
|
+
retry_callback = ->(_, _, res) { expect(res.to_s).to match(/^retried \dx$/) }
|
169
|
+
begin
|
170
|
+
HTTP.retriable(
|
171
|
+
should_retry: ->(*) { true },
|
172
|
+
tries: 3,
|
173
|
+
delay: 0,
|
174
|
+
on_retry: retry_callback
|
175
|
+
).get "#{dummy.endpoint}/retry-2"
|
176
|
+
rescue HTTP::Error => e
|
177
|
+
err = e
|
178
|
+
end
|
179
|
+
|
180
|
+
expect(err.response.to_s).to eq "retried 3x"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
155
184
|
context "posting forms to resources" do
|
156
185
|
it "is easy" do
|
157
186
|
response = HTTP.post "#{dummy.endpoint}/form", :form => {:example => "testing-form"}
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,11 @@ class DummyServer < WEBrick::HTTPServer
|
|
18
18
|
@handlers ||= {}
|
19
19
|
end
|
20
20
|
|
21
|
+
def initialize(server, memo)
|
22
|
+
super(server)
|
23
|
+
@memo = memo
|
24
|
+
end
|
25
|
+
|
21
26
|
%w[get post head].each do |method|
|
22
27
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
23
28
|
def self.#{method}(path, &block)
|
@@ -186,5 +191,13 @@ class DummyServer < WEBrick::HTTPServer
|
|
186
191
|
res["Content-Encoding"] = "deflate"
|
187
192
|
end
|
188
193
|
end
|
194
|
+
|
195
|
+
get "/retry-2" do |_req, res|
|
196
|
+
@memo[:attempts] ||= 0
|
197
|
+
@memo[:attempts] += 1
|
198
|
+
|
199
|
+
res.body = "retried #{@memo[:attempts]}x"
|
200
|
+
res.status = @memo[:attempts] == 2 ? 200 : 500
|
201
|
+
end
|
189
202
|
end
|
190
203
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2025-06-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: addressable
|
@@ -27,20 +27,6 @@ dependencies:
|
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.8'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: base64
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
requirements:
|
34
|
-
- - "~>"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '0.1'
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.1'
|
44
30
|
- !ruby/object:Gem::Dependency
|
45
31
|
name: http-cookie
|
46
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +56,7 @@ dependencies:
|
|
70
56
|
- !ruby/object:Gem::Version
|
71
57
|
version: '2.2'
|
72
58
|
- !ruby/object:Gem::Dependency
|
73
|
-
name: llhttp
|
59
|
+
name: llhttp
|
74
60
|
requirement: !ruby/object:Gem::Requirement
|
75
61
|
requirements:
|
76
62
|
- - "~>"
|
@@ -111,6 +97,7 @@ files:
|
|
111
97
|
- ".rubocop.yml"
|
112
98
|
- ".rubocop/layout.yml"
|
113
99
|
- ".rubocop/metrics.yml"
|
100
|
+
- ".rubocop/rspec.yml"
|
114
101
|
- ".rubocop/style.yml"
|
115
102
|
- ".rubocop_todo.yml"
|
116
103
|
- ".yardopts"
|
@@ -125,6 +112,7 @@ files:
|
|
125
112
|
- SECURITY.md
|
126
113
|
- http.gemspec
|
127
114
|
- lib/http.rb
|
115
|
+
- lib/http/base64.rb
|
128
116
|
- lib/http/chainable.rb
|
129
117
|
- lib/http/client.rb
|
130
118
|
- lib/http/connection.rb
|
@@ -136,9 +124,11 @@ files:
|
|
136
124
|
- lib/http/features/instrumentation.rb
|
137
125
|
- lib/http/features/logging.rb
|
138
126
|
- lib/http/features/normalize_uri.rb
|
127
|
+
- lib/http/features/raise_error.rb
|
139
128
|
- lib/http/headers.rb
|
140
129
|
- lib/http/headers/known.rb
|
141
130
|
- lib/http/headers/mixin.rb
|
131
|
+
- lib/http/headers/normalizer.rb
|
142
132
|
- lib/http/mime_type.rb
|
143
133
|
- lib/http/mime_type/adapter.rb
|
144
134
|
- lib/http/mime_type/json.rb
|
@@ -153,6 +143,10 @@ files:
|
|
153
143
|
- lib/http/response/parser.rb
|
154
144
|
- lib/http/response/status.rb
|
155
145
|
- lib/http/response/status/reasons.rb
|
146
|
+
- lib/http/retriable/client.rb
|
147
|
+
- lib/http/retriable/delay_calculator.rb
|
148
|
+
- lib/http/retriable/errors.rb
|
149
|
+
- lib/http/retriable/performer.rb
|
156
150
|
- lib/http/timeout/global.rb
|
157
151
|
- lib/http/timeout/null.rb
|
158
152
|
- lib/http/timeout/per_operation.rb
|
@@ -166,7 +160,9 @@ files:
|
|
166
160
|
- spec/lib/http/features/auto_inflate_spec.rb
|
167
161
|
- spec/lib/http/features/instrumentation_spec.rb
|
168
162
|
- spec/lib/http/features/logging_spec.rb
|
163
|
+
- spec/lib/http/features/raise_error_spec.rb
|
169
164
|
- spec/lib/http/headers/mixin_spec.rb
|
165
|
+
- spec/lib/http/headers/normalizer_spec.rb
|
170
166
|
- spec/lib/http/headers_spec.rb
|
171
167
|
- spec/lib/http/options/body_spec.rb
|
172
168
|
- spec/lib/http/options/features_spec.rb
|
@@ -185,6 +181,8 @@ files:
|
|
185
181
|
- spec/lib/http/response/parser_spec.rb
|
186
182
|
- spec/lib/http/response/status_spec.rb
|
187
183
|
- spec/lib/http/response_spec.rb
|
184
|
+
- spec/lib/http/retriable/delay_calculator_spec.rb
|
185
|
+
- spec/lib/http/retriable/performer_spec.rb
|
188
186
|
- spec/lib/http/uri/normalizer_spec.rb
|
189
187
|
- spec/lib/http/uri_spec.rb
|
190
188
|
- spec/lib/http_spec.rb
|
@@ -209,7 +207,7 @@ metadata:
|
|
209
207
|
source_code_uri: https://github.com/httprb/http
|
210
208
|
wiki_uri: https://github.com/httprb/http/wiki
|
211
209
|
bug_tracker_uri: https://github.com/httprb/http/issues
|
212
|
-
changelog_uri: https://github.com/httprb/http/blob/v5.
|
210
|
+
changelog_uri: https://github.com/httprb/http/blob/v5.3.0/CHANGELOG.md
|
213
211
|
rubygems_mfa_required: 'true'
|
214
212
|
post_install_message:
|
215
213
|
rdoc_options: []
|
@@ -226,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
224
|
- !ruby/object:Gem::Version
|
227
225
|
version: '0'
|
228
226
|
requirements: []
|
229
|
-
rubygems_version: 3.
|
227
|
+
rubygems_version: 3.4.19
|
230
228
|
signing_key:
|
231
229
|
specification_version: 4
|
232
230
|
summary: HTTP should be easy
|
@@ -238,7 +236,9 @@ test_files:
|
|
238
236
|
- spec/lib/http/features/auto_inflate_spec.rb
|
239
237
|
- spec/lib/http/features/instrumentation_spec.rb
|
240
238
|
- spec/lib/http/features/logging_spec.rb
|
239
|
+
- spec/lib/http/features/raise_error_spec.rb
|
241
240
|
- spec/lib/http/headers/mixin_spec.rb
|
241
|
+
- spec/lib/http/headers/normalizer_spec.rb
|
242
242
|
- spec/lib/http/headers_spec.rb
|
243
243
|
- spec/lib/http/options/body_spec.rb
|
244
244
|
- spec/lib/http/options/features_spec.rb
|
@@ -257,6 +257,8 @@ test_files:
|
|
257
257
|
- spec/lib/http/response/parser_spec.rb
|
258
258
|
- spec/lib/http/response/status_spec.rb
|
259
259
|
- spec/lib/http/response_spec.rb
|
260
|
+
- spec/lib/http/retriable/delay_calculator_spec.rb
|
261
|
+
- spec/lib/http/retriable/performer_spec.rb
|
260
262
|
- spec/lib/http/uri/normalizer_spec.rb
|
261
263
|
- spec/lib/http/uri_spec.rb
|
262
264
|
- spec/lib/http_spec.rb
|