File tree 4 files changed +19
-10
lines changed
4 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,4 @@ test/tmp
16
16
test /version_tmp
17
17
tmp
18
18
* ~
19
+ nbproject /*
Original file line number Diff line number Diff line change 1
1
# Limiter
2
2
3
- TODO: Write a gem description
3
+ Rack middleware for rate-limiting incoming HTTP requests with black_list and white_list support.
4
4
5
5
## Installation
6
6
7
7
Add this line to your application's Gemfile:
8
8
9
- gem 'limiter'
9
+ gem 'limiter', :git => "git://github.com/csdn-dev/limiter.git"
10
10
11
11
And then execute:
12
12
13
13
$ bundle
14
14
15
- Or install it yourself as:
16
-
17
- $ gem install limiter
18
-
19
15
## Usage
20
16
21
- TODO: Write usage instructions here
17
+ ``` ruby
18
+ # config/initializers/limiter.rb
19
+ require File .expand_path(" ../redis" , __FILE__ )
20
+ Rails .configuration.app_middleware.insert_before(Rack ::MethodOverride ,
21
+ Limiter ::RateLimiter ,
22
+ :black_list => Limiter ::BlackList .new ($redis ),
23
+ :white_list => Limiter ::WhiteList .new ($redis ),
24
+ :allow_path => Rails .env.development? ? /^\/ (assets|human_validations|simple_captcha) / :
25
+ /^\/ (human_validations|simple_captcha) / ,
26
+ :message => " <a href='/human_validations/new'>我不是机器人</a>" ,
27
+ :visit_counter => Limiter ::VisitCounter .new ($redis )
28
+ )
29
+ ```
22
30
23
31
## Contributing
24
32
Original file line number Diff line number Diff line change @@ -113,8 +113,8 @@ def rate_limit_exceeded
113
113
# @param [Hash{String => String}] headers
114
114
# @return [Array(Integer, Hash, #each)]
115
115
def http_error ( code , message = nil , headers = { } )
116
- [ code , { 'Content-Type' => 'text/plain ; charset=utf-8' } . merge ( headers ) ,
117
- http_status ( code ) + ( message . nil? ? "\n " : " (#{ message } )\n " ) ]
116
+ [ code , { 'Content-Type' => 'text/html ; charset=utf-8' } . merge ( headers ) ,
117
+ [ http_status ( code ) + ( message . nil? ? "\n " : " (#{ message } )\n " ) ] ]
118
118
end
119
119
120
120
##
Original file line number Diff line number Diff line change 1
1
# -*- encoding : utf-8 -*-
2
2
module Limiter
3
- VERSION = "0.0.1 "
3
+ VERSION = "0.0.2 "
4
4
end
You can’t perform that action at this time.
0 commit comments