rack-throttle 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack/throttle/rules.rb +18 -5
- data/lib/rack/throttle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff38a72f8ae91886b4c8db0cf2abab7ed33d908f19bf676b2d013f06a270d846
|
4
|
+
data.tar.gz: 3bed6513dc33088624b4abfca5ab9edd56bee3aabfab7fec69d08dc627084efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a158cf9982fe6790481e861974a34a5c496d861c5af791b72d07548375a94bd7228bb9a63ad9736433316d86d0ca552690bd764a3eb758222edaa728213703f
|
7
|
+
data.tar.gz: ae8658e3cc10b7ae80ea684f6b8cb4e34876f9c4915416d37f71f556a3e497a02ac5ca2d277dd4fa35c71cc07b368c109af6167b3cf8d11e57beb4406841b43b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/lib/rack/throttle/rules.rb
CHANGED
@@ -14,7 +14,7 @@ module Rack
|
|
14
14
|
def rules
|
15
15
|
@rules ||= begin
|
16
16
|
rs = options[:rules]
|
17
|
-
rs.sort_by { |r| r[:path].to_s }.reverse
|
17
|
+
rs.sort_by { |r| [r[:proc].to_s, r[:path].to_s] }.reverse
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -32,7 +32,7 @@ module Rack
|
|
32
32
|
|
33
33
|
def whitelisted?(request)
|
34
34
|
return true if ip_whitelisted?(IPAddr.new(ip(request)))
|
35
|
-
return true if
|
35
|
+
return true if rule_whitelisted?(request)
|
36
36
|
false
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,7 @@ module Rack
|
|
40
40
|
!!ips.find { |ip| ip.include?(request_ip) }
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def rule_whitelisted?(request)
|
44
44
|
rule = rule_for(request)
|
45
45
|
rule ? rule[:whitelisted] : false
|
46
46
|
end
|
@@ -48,7 +48,8 @@ module Rack
|
|
48
48
|
def rule_for(request)
|
49
49
|
rules.find do |rule|
|
50
50
|
next unless rule[:method] == request.request_method.to_s
|
51
|
-
next
|
51
|
+
next if rule[:proc] && rule[:proc].call(request) == false
|
52
|
+
next if rule[:path] && !path_matches?(rule, request.path.to_s)
|
52
53
|
rule
|
53
54
|
end
|
54
55
|
end
|
@@ -66,11 +67,23 @@ module Rack
|
|
66
67
|
|
67
68
|
def client_identifier(request)
|
68
69
|
if (rule = rule_for(request))
|
69
|
-
|
70
|
+
client_identifier_for_rule(request, rule)
|
70
71
|
else
|
71
72
|
ip(request)
|
72
73
|
end
|
73
74
|
end
|
75
|
+
|
76
|
+
def client_identifier_for_rule(request, rule)
|
77
|
+
if rule[:proc]
|
78
|
+
"#{rule[:method]}_#{rule[:proc].call(request)}"
|
79
|
+
elsif rule[:path]
|
80
|
+
"#{ip(request)}_#{rule[:method]}_#{rule[:path]}"
|
81
|
+
elsif rule[:method]
|
82
|
+
"#{ip(request)}_#{rule[:method]}"
|
83
|
+
else
|
84
|
+
raise NotImplementedError
|
85
|
+
end
|
86
|
+
end
|
74
87
|
|
75
88
|
def ip(request)
|
76
89
|
request.ip.to_s
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-throttle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arto Bendiken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|