File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 11class Rack ::Attack
2+ Rack ::Attack . cache . store = ActiveSupport ::Cache ::MemoryStore . new
3+
4+ # 10 requests per 10 seconds for a single ip
5+ throttle ( 'req/ip' , limit : 10 , period : 10 ) do |req |
6+ req . ip
7+ end
8+
9+ # whitelist localhost
10+ Rack ::Attack ::safelist ( 'allow-localhost' ) do |req |
11+ '127.0.0.1' == req . ip || '::1' == req . ip
12+ end
13+
214 # response with 429
315 self . throttled_response = -> ( env ) {
416 retry_after = ( env [ 'rack.attack.match_data' ] || { } ) [ :period ]
@@ -9,13 +21,3 @@ class Rack::Attack
921 ]
1022 }
1123end
12-
13- # 10 requests per 10 seconds for a single ip
14- Rack ::Attack ::throttle ( 'req/ip' , limit : 10 , period : 10 ) do |req |
15- req . ip
16- end
17-
18- # whitelist localhost
19- Rack ::Attack ::safelist ( 'allow-localhost' ) do |req |
20- '127.0.0.1' == req . ip || '::1' == req . ip
21- end
You can’t perform that action at this time.
0 commit comments