diff --git a/CHANGELOG.md b/CHANGELOG.md index f0509bf..857a14f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changlog +## v2.3.0 - unlreleased (master) + * Allow throttle `limit` argument to be a proc. (thanks @lunks) + ## v2.2.1 - 13 August 2013 * Add license to gemspec * Support ruby version 1.9.2 diff --git a/README.md b/README.md index 3ccb950..0f78744 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ The algorithm is actually more concise in code: See [Rack::Attack.call](https:// ## Usage -Define whitelists, blacklists, throttles, and tracks as blocks that return truthy values if matched, falsy otherwise. In a Rails app +Define whitelists, blacklists, throttles, and tracks as blocks that return truthy values if matched, falsy otherwise. In a Rails app these go in an initializer in `config/initializers/`. A [Rack::Request](http://rack.rubyforge.org/doc/classes/Rack/Request.html) object is passed to the block (named 'req' in the examples). @@ -150,7 +150,7 @@ how the parameters work. # You can also set a limit using a proc instead of a number. For # instance, after Rack::Auth::Basic has authenticated the user: - limit_based_on_proc = proc {|req| req.env["REMOTE_USER"] == "god" ? 100 : 1} + limit_based_on_proc = proc {|req| req.env["REMOTE_USER"] == "admin" ? 100 : 1} Rack::Attack.throttle('req/ip', :limit => limit_based_on_proc, :period => 1.second) do |req| req.ip end @@ -218,9 +218,9 @@ You can subscribe to 'rack.attack' events and log it, graph it, etc: ## Testing -A note on developing and testing apps using Rack::Attack - if you are using throttling in particular, you will -need to enable the cache in your development environment. See [Caching with Rails](http://guides.rubyonrails.org/caching_with_rails.html) -for more on how to do this. +A note on developing and testing apps using Rack::Attack - if you are using throttling in particular, you will +need to enable the cache in your development environment. See [Caching with Rails](http://guides.rubyonrails.org/caching_with_rails.html) +for more on how to do this. ## Performance diff --git a/lib/rack/attack/version.rb b/lib/rack/attack/version.rb index 2fe4e47..3b7a47c 100644 --- a/lib/rack/attack/version.rb +++ b/lib/rack/attack/version.rb @@ -1,5 +1,5 @@ module Rack module Attack - VERSION = '2.2.1' + VERSION = '2.3.0' end end diff --git a/spec/rack_attack_throttle_spec.rb b/spec/rack_attack_throttle_spec.rb index 5b40ace..e1a90da 100644 --- a/spec/rack_attack_throttle_spec.rb +++ b/spec/rack_attack_throttle_spec.rb @@ -43,7 +43,7 @@ describe 'Rack::Attack.throttle with limit as proc' do before do @period = 60 # Use a long period; failures due to cache key rotation less likely Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new - Rack::Attack.throttle('ip/sec', :limit => lambda {|env| 1}, :period => @period) { |req| req.ip } + Rack::Attack.throttle('ip/sec', :limit => lambda {|req| 1}, :period => @period) { |req| req.ip } end allow_ok_requests