puffing-billy 0.9.2 → 0.10.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/CHANGELOG.md +5 -0
- data/Gemfile.lock +2 -2
- data/README.md +7 -0
- data/lib/billy/config.rb +5 -2
- data/lib/billy/handlers/cache_handler.rb +7 -2
- data/lib/billy/version.rb +1 -1
- data/spec/lib/billy/handlers/cache_handler_spec.rb +49 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc029e59d0433abc3e3cafc5a7a8e473fc81d2ba
|
4
|
+
data.tar.gz: 9c9098d75fd2b8a2657a58ebf7264d503391523c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deecb813ec9e291ecf787fcf4c7fc01c514521908ccbae514fe25cc2eef01ce52fb8af233f41eb3d64d070bbade8ba610c437bcbcdfe3ed6d45a6af1c676b871
|
7
|
+
data.tar.gz: c0916575398630111b70ae5f333986d25dcd7a52958fada47986e62347e9a9d44d0ce6e4dab72a5845cf0cbe9755b92269087b0848bc46e50057c940266ce3b5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.10.0, 2017-04-06
|
2
|
+
-------------------
|
3
|
+
* Allow to simulate network delays when responding from cache [#182](https://github.com/oesmith/puffing-billy/pull/182)
|
4
|
+
* Allow the dynamic jsonp callback name to be configured [#185](https://github.com/oesmith/puffing-billy/pull/185)
|
5
|
+
|
1
6
|
v0.9.2, 2017-01-18
|
2
7
|
------------------
|
3
8
|
* Ensure that files are closed after being opened [#175](https://github.com/oesmith/puffing-billy/pull/175)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -291,6 +291,9 @@ using `c.dynamic_jsonp`. This is helpful when JSONP APIs use cache-busting
|
|
291
291
|
parameters. For example, if you want `http://example.com/foo?callback=bar&id=1&cache_bust=12345` and `http://example.com/foo?callback=baz&id=1&cache_bust=98765` to be cache hits for each other, you would set `c.dynamic_jsonp_keys = ['callback', 'cache_bust']` to ignore both params. Note
|
292
292
|
that in this example the `id` param would still be considered important.
|
293
293
|
|
294
|
+
`c.dynamic_jsonp_callback_name` is used to configure the name of the JSONP callback
|
295
|
+
parameter. The default is `callback`.
|
296
|
+
|
294
297
|
`c.path_blacklist = []` is used to always cache specific paths on any hostnames,
|
295
298
|
including whitelisted ones. This is useful if your AUT has routes that get data
|
296
299
|
from external services, such as `/api` where the ajax request is a local URL but
|
@@ -346,6 +349,10 @@ Billy.configure do |c|
|
|
346
349
|
end
|
347
350
|
```
|
348
351
|
|
352
|
+
`c.cache_simulates_network_delays` is used to add some delay before cache returns response. When set to `true`, cached requests will wait from configured delay time before responding. This allows to catch various race conditions in asynchronous front-end requests. The default is `false`.
|
353
|
+
|
354
|
+
`c.cache_simulates_network_delay_time` is used to configure time (in seconds) to wait until responding from cache. The default is `0.1`.
|
355
|
+
|
349
356
|
### Cache Scopes
|
350
357
|
|
351
358
|
If you need to cache different responses to the same HTTP request, you can use
|
data/lib/billy/config.rb
CHANGED
@@ -9,9 +9,9 @@ module Billy
|
|
9
9
|
attr_accessor :logger, :cache, :cache_request_headers, :whitelist, :path_blacklist, :ignore_params,
|
10
10
|
:persist_cache, :ignore_cache_port, :non_successful_cache_disabled, :non_successful_error_level,
|
11
11
|
:non_whitelisted_requests_disabled, :cache_path, :proxy_host, :proxy_port, :proxied_request_inactivity_timeout,
|
12
|
-
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :merge_cached_responses_whitelist,
|
12
|
+
:proxied_request_connect_timeout, :dynamic_jsonp, :dynamic_jsonp_keys, :dynamic_jsonp_callback_name, :merge_cached_responses_whitelist,
|
13
13
|
:strip_query_params, :proxied_request_host, :proxied_request_port, :cache_request_body_methods, :after_cache_handles_request,
|
14
|
-
:record_stub_requests
|
14
|
+
:cache_simulates_network_delays, :cache_simulates_network_delay_time, :record_stub_requests
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
@@ -28,6 +28,7 @@ module Billy
|
|
28
28
|
@persist_cache = false
|
29
29
|
@dynamic_jsonp = false
|
30
30
|
@dynamic_jsonp_keys = ['callback']
|
31
|
+
@dynamic_jsonp_callback_name = 'callback'
|
31
32
|
@ignore_cache_port = true
|
32
33
|
@non_successful_cache_disabled = false
|
33
34
|
@non_successful_error_level = :warn
|
@@ -42,6 +43,8 @@ module Billy
|
|
42
43
|
@proxied_request_port = 80
|
43
44
|
@cache_request_body_methods = ['post']
|
44
45
|
@after_cache_handles_request = nil
|
46
|
+
@cache_simulates_network_delays = false
|
47
|
+
@cache_simulates_network_delay_time = 0.1
|
45
48
|
@record_stub_requests = false
|
46
49
|
end
|
47
50
|
end
|
@@ -30,6 +30,10 @@ module Billy
|
|
30
30
|
Billy.config.after_cache_handles_request.call(request, response)
|
31
31
|
end
|
32
32
|
|
33
|
+
if Billy.config.cache_simulates_network_delays
|
34
|
+
Kernel.sleep(Billy.config.cache_simulates_network_delay_time)
|
35
|
+
end
|
36
|
+
|
33
37
|
return response
|
34
38
|
end
|
35
39
|
end
|
@@ -46,8 +50,9 @@ module Billy
|
|
46
50
|
request_uri = Addressable::URI.parse(url)
|
47
51
|
if request_uri.query
|
48
52
|
params = CGI.parse(request_uri.query)
|
49
|
-
|
50
|
-
|
53
|
+
callback_name = Billy.config.dynamic_jsonp_callback_name
|
54
|
+
if params[callback_name].any? && response[:content].match(/\w+\(/)
|
55
|
+
response[:content].sub!(/\w+\(/, params[callback_name].first + '(')
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
data/lib/billy/version.rb
CHANGED
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Billy::CacheHandler do
|
4
4
|
let(:handler) { Billy::CacheHandler.new }
|
5
|
+
let(:request_url) { 'http://example.test:8080/index?some=param&callback=dynamicCallback5678' }
|
5
6
|
let(:request) do
|
6
7
|
{
|
7
8
|
method: 'post',
|
8
|
-
url:
|
9
|
+
url: request_url,
|
9
10
|
headers: { 'Accept-Encoding' => 'gzip',
|
10
11
|
'Cache-Control' => 'no-cache' },
|
11
12
|
body: 'Some body'
|
@@ -114,6 +115,26 @@ describe Billy::CacheHandler do
|
|
114
115
|
request[:body])).to eql(status: 200, headers: { 'Connection' => 'close', 'Access-Control-Allow-Origin' => "*" }, content: 'Some body')
|
115
116
|
end
|
116
117
|
end
|
118
|
+
|
119
|
+
context 'when dynamic_jsonp_callback_name is set' do
|
120
|
+
let(:dynamic_jsonp_callback_name) { 'customCallback' }
|
121
|
+
let(:request_url) { "http://example.test:8080/index?some=param&#{dynamic_jsonp_callback_name}=dynamicCallback5678" }
|
122
|
+
|
123
|
+
before do
|
124
|
+
allow(Billy.config).to receive(:dynamic_jsonp_callback_name) do
|
125
|
+
dynamic_jsonp_callback_name
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should call the callback with the specified name' do
|
130
|
+
expect(Billy::Cache.instance).to receive(:cached?).and_return(true)
|
131
|
+
expect(Billy::Cache.instance).to receive(:fetch).and_return(status: 200, headers: { 'Connection' => 'close' }, content: 'dynamicCallback1234({"yolo":"kitten"})')
|
132
|
+
expect(handler.handle_request(request[:method],
|
133
|
+
request[:url],
|
134
|
+
request[:headers],
|
135
|
+
request[:body])).to eql(status: 200, headers: { 'Connection' => 'close' }, content: 'dynamicCallback5678({"yolo":"kitten"})')
|
136
|
+
end
|
137
|
+
end
|
117
138
|
end
|
118
139
|
|
119
140
|
context 'updating jsonp callback names disabled' do
|
@@ -139,5 +160,32 @@ describe Billy::CacheHandler do
|
|
139
160
|
request[:headers],
|
140
161
|
request[:body])).to be nil
|
141
162
|
end
|
163
|
+
|
164
|
+
context 'network delay simulation' do
|
165
|
+
before do
|
166
|
+
allow(Billy::Cache.instance).to receive(:cached?).and_return(true)
|
167
|
+
allow(Billy::Cache.instance).to receive(:fetch).and_return(status: 200, headers: { 'Connection' => 'close' }, content: 'dynamicCallback1234({"yolo":"kitten"})')
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when cache_simulates_network_delays is disabled' do
|
171
|
+
it 'does not sleep for default delay before responding' do
|
172
|
+
expect(Kernel).not_to receive(:sleep)
|
173
|
+
handler.handle_request(request[:method], request[:url], request[:headers], request[:body])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when cache_simulates_network_delays is enabled' do
|
178
|
+
around do |example|
|
179
|
+
Billy.config.cache_simulates_network_delays = true
|
180
|
+
example.call
|
181
|
+
Billy.config.cache_simulates_network_delays = false
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'sleeps for default delay before responding' do
|
185
|
+
expect(Kernel).to receive(:sleep).with(Billy.config.cache_simulates_network_delay_time)
|
186
|
+
handler.handle_request(request[:method], request[:url], request[:headers], request[:body])
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
142
190
|
end
|
143
191
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puffing-billy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olly Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -386,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
386
386
|
version: '0'
|
387
387
|
requirements: []
|
388
388
|
rubyforge_project:
|
389
|
-
rubygems_version: 2.
|
389
|
+
rubygems_version: 2.5.2
|
390
390
|
signing_key:
|
391
391
|
specification_version: 4
|
392
392
|
summary: Easy request stubs for browser tests.
|
@@ -411,4 +411,3 @@ test_files:
|
|
411
411
|
- spec/lib/proxy_spec.rb
|
412
412
|
- spec/spec_helper.rb
|
413
413
|
- spec/support/test_server.rb
|
414
|
-
has_rdoc:
|