lhc 7.0.1 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/docs/interceptors.md +2 -0
- data/docs/interceptors/default_timeout.md +17 -0
- data/lib/lhc.rb +2 -0
- data/lib/lhc/interceptor.rb +2 -0
- data/lib/lhc/interceptors/default_timeout.rb +14 -0
- data/lib/lhc/request.rb +1 -0
- data/lib/lhc/version.rb +1 -1
- data/spec/interceptors/default_timeout/main_spec.rb +32 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad563c7a18adf9ec842d204bed81599304dac1c4
|
4
|
+
data.tar.gz: ef62b6ce7f4b80475ee0adbb4c502e6918706d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1a310cd83690e9aeea40affabae0c47eda9abaccac038efb52440d806cb675b410b4dd0252989e88cb9b529fb6b9d4525029cb63d3a2f2385e3d9ed3750db5
|
7
|
+
data.tar.gz: 34307e36153349564b30d2e5aeb62aff588911cbcd0bd3646aab83ba0c05b484b39d00c5c6b1bb7774a97ef6e488d984c05b364c150a990939264d8266c10093
|
data/README.md
CHANGED
@@ -112,6 +112,21 @@ You can configure global endpoints, placeholders and interceptors.
|
|
112
112
|
|
113
113
|
→ [Read more about configuration](docs/configuration.md)
|
114
114
|
|
115
|
+
## Timeout
|
116
|
+
|
117
|
+
Working and configuring timeouts is important, to ensure your app stays alive when services you depend on start to get really slow...
|
118
|
+
|
119
|
+
LHC forwards two timeout options directly to typhoeus:
|
120
|
+
|
121
|
+
`timeout` (in seconds) - The maximum time in seconds that you allow the libcurl transfer operation to take. Normally, name lookups can take a considerable time and limiting operations to less than a few seconds risk aborting perfectly normal operations. This option may cause libcurl to use the SIGALRM signal to timeout system calls.
|
122
|
+
`connecttimeout` (in seconds) - It should contain the maximum time in seconds that you allow the connection phase to the server to take. This only limits the connection phase, it has no impact once it has connected. Set to zero to switch to the default built-in connection timeout - 300 seconds.
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
LHC.get('http://local.ch', timeout: 5, connecttimeout: 1)
|
126
|
+
```
|
127
|
+
|
128
|
+
LHC provides a [timeout interceptor](docs/interceptors/default_timeout.md) that lets you apply default timeout values to all the requests that you are performig in your application.
|
129
|
+
|
115
130
|
## URL-Templates
|
116
131
|
|
117
132
|
Instead of using concrete urls you can also use url-templates that contain placeholders.
|
data/docs/interceptors.md
CHANGED
@@ -27,6 +27,8 @@ like [Caching](/docs/interceptors/caching.md), [Monitoring](/docs/interceptors/m
|
|
27
27
|
|
28
28
|
## Callbacks
|
29
29
|
|
30
|
+
`before_raw_request(request)` is called before the raw typhoeus request is prepared/created.
|
31
|
+
|
30
32
|
`before_request(request)` is called when the request is prepared and about to be executed.
|
31
33
|
|
32
34
|
`after_request(request)` is called after request was started.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Default Timeout Interceptor
|
2
|
+
|
3
|
+
Applies default timeout values to all requests made in an application, that uses LHC.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
LHC.config.interceptors = [LHC::DefaultTimeout]
|
7
|
+
```
|
8
|
+
|
9
|
+
`timeout` default: 15 seconds
|
10
|
+
`connecttimeout` default: 1 second
|
11
|
+
|
12
|
+
## Overwrite defaults
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
LHC::DefaultTimeout.timeout = 5 # seconds
|
16
|
+
LHC::DefaultTimeout.connecttimeout = 2 # seconds
|
17
|
+
```
|
data/lib/lhc.rb
CHANGED
data/lib/lhc/interceptor.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
class LHC::DefaultTimeout < LHC::Interceptor
|
2
|
+
include ActiveSupport::Configurable
|
3
|
+
|
4
|
+
config_accessor :timeout, :connecttimeout
|
5
|
+
|
6
|
+
CONNECTTIMEOUT = 1 # second
|
7
|
+
TIMEOUT = 15 # seconds
|
8
|
+
|
9
|
+
def before_raw_request(request)
|
10
|
+
request_options = (request.options || {})
|
11
|
+
request_options[:timeout] ||= timeout || TIMEOUT
|
12
|
+
request_options[:connecttimeout] ||= connecttimeout || CONNECTTIMEOUT
|
13
|
+
end
|
14
|
+
end
|
data/lib/lhc/request.rb
CHANGED
@@ -17,6 +17,7 @@ class LHC::Request
|
|
17
17
|
use_configured_endpoint!
|
18
18
|
generate_url_from_template!
|
19
19
|
self.iprocessor = LHC::InterceptorProcessor.new(self)
|
20
|
+
iprocessor.intercept(:before_raw_request, self)
|
20
21
|
self.raw = create_request
|
21
22
|
self.format = options.delete('format') || LHC::Formats::JSON.new
|
22
23
|
iprocessor.intercept(:before_request, self)
|
data/lib/lhc/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHC::DefaultTimeout do
|
4
|
+
before(:each) do
|
5
|
+
LHC.config.interceptors = [LHC::DefaultTimeout]
|
6
|
+
LHC::DefaultTimeout.timeout = nil
|
7
|
+
LHC::DefaultTimeout.connecttimeout = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:stub) { stub_request(:get, 'http://local.ch').to_return(status: 200, body: 'The Website') }
|
11
|
+
|
12
|
+
it 'applies default timeouts to all requests made' do
|
13
|
+
stub
|
14
|
+
expect_any_instance_of(Ethon::Easy).to receive(:http_request)
|
15
|
+
.with(anything, anything, hash_including(timeout: 15, connecttimeout: 1)).and_call_original
|
16
|
+
LHC.get('http://local.ch')
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with changed default timesouts' do
|
20
|
+
before(:each) do
|
21
|
+
LHC::DefaultTimeout.timeout = 10
|
22
|
+
LHC::DefaultTimeout.connecttimeout = 3
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'applies custom default timeouts to all requests made' do
|
26
|
+
stub
|
27
|
+
expect_any_instance_of(Ethon::Easy).to receive(:http_request)
|
28
|
+
.with(anything, anything, hash_including(timeout: 10, connecttimeout: 3)).and_call_original
|
29
|
+
LHC.get('http://local.ch')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- docs/interceptors.md
|
195
195
|
- docs/interceptors/authentication.md
|
196
196
|
- docs/interceptors/caching.md
|
197
|
+
- docs/interceptors/default_timeout.md
|
197
198
|
- docs/interceptors/monitoring.md
|
198
199
|
- docs/interceptors/prometheus.md
|
199
200
|
- docs/interceptors/retry.md
|
@@ -219,6 +220,7 @@ files:
|
|
219
220
|
- lib/lhc/interceptor_processor.rb
|
220
221
|
- lib/lhc/interceptors/auth.rb
|
221
222
|
- lib/lhc/interceptors/caching.rb
|
223
|
+
- lib/lhc/interceptors/default_timeout.rb
|
222
224
|
- lib/lhc/interceptors/monitoring.rb
|
223
225
|
- lib/lhc/interceptors/prometheus.rb
|
224
226
|
- lib/lhc/interceptors/retry.rb
|
@@ -305,6 +307,7 @@ files:
|
|
305
307
|
- spec/interceptors/caching/response_status_spec.rb
|
306
308
|
- spec/interceptors/caching/to_cache_spec.rb
|
307
309
|
- spec/interceptors/default_interceptors_spec.rb
|
310
|
+
- spec/interceptors/default_timeout/main_spec.rb
|
308
311
|
- spec/interceptors/define_spec.rb
|
309
312
|
- spec/interceptors/monitoring/main_spec.rb
|
310
313
|
- spec/interceptors/prometheus_spec.rb
|
@@ -359,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
359
362
|
requirements:
|
360
363
|
- Ruby >= 2.0.0
|
361
364
|
rubyforge_project:
|
362
|
-
rubygems_version: 2.6.
|
365
|
+
rubygems_version: 2.6.12
|
363
366
|
signing_key:
|
364
367
|
specification_version: 4
|
365
368
|
summary: LocalHttpClient
|
@@ -436,6 +439,7 @@ test_files:
|
|
436
439
|
- spec/interceptors/caching/response_status_spec.rb
|
437
440
|
- spec/interceptors/caching/to_cache_spec.rb
|
438
441
|
- spec/interceptors/default_interceptors_spec.rb
|
442
|
+
- spec/interceptors/default_timeout/main_spec.rb
|
439
443
|
- spec/interceptors/define_spec.rb
|
440
444
|
- spec/interceptors/monitoring/main_spec.rb
|
441
445
|
- spec/interceptors/prometheus_spec.rb
|