http 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +10 -0
- data/README.md +13 -4
- data/lib/http/chainable.rb +2 -2
- data/lib/http/version.rb +1 -1
- data/spec/lib/http_spec.rb +58 -0
- metadata +3 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04013fb3be8785ffad986b70b2d8110e47d88a8a
|
4
|
+
data.tar.gz: edaf6a058cb71d10dd3195830bbe20287b4f673a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea10d0cffd4711074a4337d7ef2255593af098221d18776d9a9d0dd0815976d348eae4f9c9d825229fd6e5f5404a7f25efd8231214b16a1ed1dcbeba706b4fe
|
7
|
+
data.tar.gz: 2d37693d17444f69f62e2951549b0269fd962ef7f8f302584065a8d37ceb38ffc3d9a98832120b9327eaf2c16d17c8805c9c30e77858b0b33fe910b5c4f7ecc5
|
data/CHANGES.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
* _the future is unwritten_
|
4
4
|
|
5
5
|
|
6
|
+
## 0.8.7 (2015-05-08)
|
7
|
+
|
8
|
+
* Fix `HTTP.timeout` API with options only given. (@ixti)
|
9
|
+
|
10
|
+
|
11
|
+
## 0.8.6 (2015-05-08)
|
12
|
+
|
13
|
+
* Reset global timeouts after the request finishes. See #215. (@zanker)
|
14
|
+
|
15
|
+
|
6
16
|
## 0.8.5 (2015-05-06)
|
7
17
|
|
8
18
|
* Add simple timeouts configuration API. See #205. (@ixti)
|
data/README.md
CHANGED
@@ -277,18 +277,27 @@ storage URL supported by rack-cache is supported by http.rb's cache.
|
|
277
277
|
|
278
278
|
### Timeouts
|
279
279
|
|
280
|
-
By default, HTTP does not timeout on a request. You can enable per operation
|
280
|
+
By default, HTTP does not timeout on a request. You can enable per operation
|
281
|
+
(each read/write/connect call) or global (sum of all read/write/connect calls).
|
281
282
|
|
282
283
|
Per operation timeouts are what `Net::HTTP` and the majority of HTTP clients do:
|
283
284
|
|
284
285
|
``` ruby
|
285
|
-
HTTP.timeout(:per_operation, :write => 2, :connect => 5, :read => 10)
|
286
|
+
HTTP.timeout(:per_operation, :write => 2, :connect => 5, :read => 10)
|
287
|
+
.get "http://example.com"
|
288
|
+
|
289
|
+
# For convinience, you can omit timeout type in this case. So following has
|
290
|
+
# same result as the above:
|
291
|
+
|
292
|
+
HTTP.timeout(:write => 2, :connect => 5, :read => 10).get "http://example.com"
|
286
293
|
```
|
287
294
|
|
288
|
-
Global timeouts let you set an upper bound of how long a request can take,
|
295
|
+
Global timeouts let you set an upper bound of how long a request can take,
|
296
|
+
without having to rely on `Timeout.timeout`:
|
289
297
|
|
290
298
|
``` ruby
|
291
|
-
HTTP.timeout(:global, :write => 1, :connect => 1, :read => 1)
|
299
|
+
HTTP.timeout(:global, :write => 1, :connect => 1, :read => 1)
|
300
|
+
.get "http://example.com"
|
292
301
|
```
|
293
302
|
|
294
303
|
Uses a timeout of 3 seconds, for the entire `get` call.
|
data/lib/http/chainable.rb
CHANGED
@@ -81,13 +81,13 @@ module HTTP
|
|
81
81
|
# @option options [Float] :write Write timeout
|
82
82
|
# @option options [Float] :connect Connect timeout
|
83
83
|
def timeout(klass, options = {})
|
84
|
-
klass, options =
|
84
|
+
klass, options = :per_operation, klass if klass.is_a? Hash
|
85
85
|
|
86
86
|
klass = case klass.to_sym
|
87
87
|
when :null then HTTP::Timeout::Null
|
88
88
|
when :global then HTTP::Timeout::Global
|
89
89
|
when :per_operation then HTTP::Timeout::PerOperation
|
90
|
-
else fail
|
90
|
+
else fail ArgumentError, "Unsupported Timeout class: #{klass}"
|
91
91
|
end
|
92
92
|
|
93
93
|
[:read, :write, :connect].each do |k|
|
data/lib/http/version.rb
CHANGED
data/spec/lib/http_spec.rb
CHANGED
@@ -220,4 +220,62 @@ RSpec.describe HTTP do
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
end
|
223
|
+
|
224
|
+
describe ".timeout" do
|
225
|
+
context "without timeout type" do
|
226
|
+
subject(:client) { HTTP.timeout :read => 123 }
|
227
|
+
|
228
|
+
it "sets timeout_class to PerOperation" do
|
229
|
+
expect(client.default_options.timeout_class).
|
230
|
+
to be HTTP::Timeout::PerOperation
|
231
|
+
end
|
232
|
+
|
233
|
+
it "sets given timeout options" do
|
234
|
+
expect(client.default_options.timeout_options).
|
235
|
+
to eq :read_timeout => 123
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context "with :null type" do
|
240
|
+
subject(:client) { HTTP.timeout :null, :read => 123 }
|
241
|
+
|
242
|
+
it "sets timeout_class to Null" do
|
243
|
+
expect(client.default_options.timeout_class).
|
244
|
+
to be HTTP::Timeout::Null
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "with :per_operation type" do
|
249
|
+
subject(:client) { HTTP.timeout :per_operation, :read => 123 }
|
250
|
+
|
251
|
+
it "sets timeout_class to PerOperation" do
|
252
|
+
expect(client.default_options.timeout_class).
|
253
|
+
to be HTTP::Timeout::PerOperation
|
254
|
+
end
|
255
|
+
|
256
|
+
it "sets given timeout options" do
|
257
|
+
expect(client.default_options.timeout_options).
|
258
|
+
to eq :read_timeout => 123
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context "with :global type" do
|
263
|
+
subject(:client) { HTTP.timeout :global, :read => 123 }
|
264
|
+
|
265
|
+
it "sets timeout_class to Global" do
|
266
|
+
expect(client.default_options.timeout_class).
|
267
|
+
to be HTTP::Timeout::Global
|
268
|
+
end
|
269
|
+
|
270
|
+
it "sets given timeout options" do
|
271
|
+
expect(client.default_options.timeout_options).
|
272
|
+
to eq :read_timeout => 123
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
it "fails with unknown timeout type" do
|
277
|
+
expect { HTTP.timeout(:foobar, :read => 123) }.
|
278
|
+
to raise_error(ArgumentError, /foobar/)
|
279
|
+
end
|
280
|
+
end
|
223
281
|
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: 0.8.
|
4
|
+
version: 0.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -181,45 +181,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.2.2
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: HTTP should be easy
|
188
|
-
test_files:
|
189
|
-
- spec/lib/http/cache/headers_spec.rb
|
190
|
-
- spec/lib/http/cache_spec.rb
|
191
|
-
- spec/lib/http/client_spec.rb
|
192
|
-
- spec/lib/http/content_type_spec.rb
|
193
|
-
- spec/lib/http/headers/mixin_spec.rb
|
194
|
-
- spec/lib/http/headers_spec.rb
|
195
|
-
- spec/lib/http/options/body_spec.rb
|
196
|
-
- spec/lib/http/options/form_spec.rb
|
197
|
-
- spec/lib/http/options/headers_spec.rb
|
198
|
-
- spec/lib/http/options/json_spec.rb
|
199
|
-
- spec/lib/http/options/merge_spec.rb
|
200
|
-
- spec/lib/http/options/new_spec.rb
|
201
|
-
- spec/lib/http/options/proxy_spec.rb
|
202
|
-
- spec/lib/http/options_spec.rb
|
203
|
-
- spec/lib/http/redirector_spec.rb
|
204
|
-
- spec/lib/http/request/caching_spec.rb
|
205
|
-
- spec/lib/http/request/writer_spec.rb
|
206
|
-
- spec/lib/http/request_spec.rb
|
207
|
-
- spec/lib/http/response/body_spec.rb
|
208
|
-
- spec/lib/http/response/caching_spec.rb
|
209
|
-
- spec/lib/http/response/io_body_spec.rb
|
210
|
-
- spec/lib/http/response/status_spec.rb
|
211
|
-
- spec/lib/http/response/string_body_spec.rb
|
212
|
-
- spec/lib/http/response_spec.rb
|
213
|
-
- spec/lib/http_spec.rb
|
214
|
-
- spec/spec_helper.rb
|
215
|
-
- spec/support/black_hole.rb
|
216
|
-
- spec/support/capture_warning.rb
|
217
|
-
- spec/support/connection_reuse_shared.rb
|
218
|
-
- spec/support/dummy_server.rb
|
219
|
-
- spec/support/dummy_server/servlet.rb
|
220
|
-
- spec/support/http_handling_shared.rb
|
221
|
-
- spec/support/proxy_server.rb
|
222
|
-
- spec/support/servers/config.rb
|
223
|
-
- spec/support/servers/runner.rb
|
224
|
-
- spec/support/ssl_helper.rb
|
188
|
+
test_files: []
|
225
189
|
has_rdoc:
|