rack-ratelimit 1.0.0 → 1.0.1
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/lib/rack/ratelimit.rb +6 -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: e01063bca7c6d18ab0206611063a339dc7ddfad6
|
4
|
+
data.tar.gz: ffb944f15efc8239948306e4948f25c8d488e07c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64f78b469c570ade7cb6f03e301c70550adb7486b3e5a2e36de522db35d80ce769ddd7f18e18274c6a5a6da2a2a5224244268a2a6378e5e9f8e91228ab6e7b7
|
7
|
+
data.tar.gz: 0b4929fb74cd3da4a727e1ef5c0e5fbf160704e06be4e4e639df7be98e28f1dd6dada78918bd72cd2ee85d17efceb57cb123223777fda4b83a59dbcb27f7c763
|
data/lib/rack/ratelimit.rb
CHANGED
@@ -92,6 +92,11 @@ module Rack
|
|
92
92
|
@exceptions.none? { |e| e.call(env) } && @conditions.all? { |c| c.call(env) }
|
93
93
|
end
|
94
94
|
|
95
|
+
# Give subclasses an opportunity to specialize classification.
|
96
|
+
def classify(env)
|
97
|
+
@classifier.call env
|
98
|
+
end
|
99
|
+
|
95
100
|
# Handle a Rack request:
|
96
101
|
# * Check whether the rate limit applies to the request.
|
97
102
|
# * Classify the request by IP, API token, etc.
|
@@ -101,7 +106,7 @@ module Rack
|
|
101
106
|
# * If it's the first request that exceeds the limit, log it.
|
102
107
|
# * If the count doesn't exceed the limit, pass through the request.
|
103
108
|
def call(env)
|
104
|
-
if apply_rate_limit?(env) && classification =
|
109
|
+
if apply_rate_limit?(env) && classification = classify(env)
|
105
110
|
|
106
111
|
# Marks the end of the current rate-limiting window.
|
107
112
|
timestamp = @period * (Time.now.to_f / @period).ceil
|