rack-pooledthrottle 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rack/pooledthrottle/throttle.rb +17 -5
- data/lib/rack/pooledthrottle/version.rb +1 -1
- data/spec/memecached_spec.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 609e48e88cc5bdf316fc4c338d6a6ba797f3c47c
|
4
|
+
data.tar.gz: 4f4b687d62cdd26a8cb428a01b798c8d3ed274fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93cdde36423b6acd0504b487a9f26668a338f9b9dc3e801373fd77b7a1f8ef09983cbe85b1429df5d20f6ebd695410583c7dea7b4de4f7152bdea069919b5933
|
7
|
+
data.tar.gz: 43429d571f259b333d9cb978c5708c70922e469c45b34e8ef03ce2b6f3590b7ce31a22c180e832329352d3dc2157664b4a1c83a1272b4a95b9d1ce5f8badfbb7
|
@@ -13,13 +13,25 @@ module Rack
|
|
13
13
|
end
|
14
14
|
|
15
15
|
protected
|
16
|
+
|
17
|
+
def throttled_request?(request)
|
18
|
+
if f = options[:throttled_request]
|
19
|
+
f.call(request)
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
16
24
|
|
17
25
|
def allowed?(request)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
26
|
+
if throttled_request?(request)
|
27
|
+
case
|
28
|
+
when whitelisted?(request) then true
|
29
|
+
when blacklisted?(request) then false
|
30
|
+
else
|
31
|
+
query_cache?(request)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
true
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
data/spec/memecached_spec.rb
CHANGED
@@ -28,11 +28,19 @@ describe Rack::PooledThrottle::MemcachedThrottle do
|
|
28
28
|
expect(last_response.body).to show_allowed_response
|
29
29
|
end
|
30
30
|
|
31
|
-
it 'expect a
|
31
|
+
it 'expect a failing message' do
|
32
32
|
4.times {get '/foo'}
|
33
33
|
expect(last_response.body).to show_throttled_response
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'expect a failing message' do
|
37
|
+
@options[:max] = 0
|
38
|
+
@options[:message] = 'GO AWAY!'
|
39
|
+
get '/foo'
|
40
|
+
expect(last_response.body).to match(/GO AWAY/)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
36
44
|
it "should return true if whitelisted" do
|
37
45
|
allow(app).to receive(:whitelisted?).and_return(true)
|
38
46
|
4.times {get "/foo"}
|
@@ -83,5 +91,12 @@ describe Rack::PooledThrottle::MemcachedThrottle do
|
|
83
91
|
3.times {get '/foo', email: 'scott@kickofflabs.com'}
|
84
92
|
expect(last_response.body).to show_throttled_response
|
85
93
|
end
|
94
|
+
|
95
|
+
it 'should allow certain requests to not be throttled' do
|
96
|
+
@options[:max] = 0
|
97
|
+
@options[:throttled_request] = ->(request){!request.path.end_with?('foo')}
|
98
|
+
get '/foo'
|
99
|
+
expect(last_response.body).to show_allowed_response
|
100
|
+
end
|
86
101
|
|
87
102
|
end
|