mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-03-25 09:25:49 +00:00
Merge pull request #59 from tristandunn/custom-request
Add a custom request class to allow for helper methods.
This commit is contained in:
commit
f872f5140c
3 changed files with 28 additions and 2 deletions
|
|
@ -10,7 +10,8 @@ class Rack::Attack
|
|||
autoload :Track, 'rack/attack/track'
|
||||
autoload :StoreProxy,'rack/attack/store_proxy'
|
||||
autoload :Fail2Ban, 'rack/attack/fail2ban'
|
||||
autoload :Allow2Ban, 'rack/attack/allow2ban'
|
||||
autoload :Allow2Ban, 'rack/attack/allow2ban'
|
||||
autoload :Request, 'rack/attack/request'
|
||||
|
||||
class << self
|
||||
|
||||
|
|
@ -88,7 +89,7 @@ class Rack::Attack
|
|||
end
|
||||
|
||||
def call(env)
|
||||
req = Rack::Request.new(env)
|
||||
req = Rack::Attack::Request.new(env)
|
||||
|
||||
if whitelisted?(req)
|
||||
@app.call(env)
|
||||
|
|
|
|||
6
lib/rack/attack/request.rb
Normal file
6
lib/rack/attack/request.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
module Rack
|
||||
class Attack
|
||||
class Request < ::Rack::Request
|
||||
end
|
||||
end
|
||||
end
|
||||
19
spec/rack_attack_request_spec.rb
Normal file
19
spec/rack_attack_request_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'Rack::Attack' do
|
||||
describe 'helpers' do
|
||||
before do
|
||||
class Rack::Attack::Request
|
||||
def remote_ip
|
||||
ip
|
||||
end
|
||||
end
|
||||
|
||||
Rack::Attack.whitelist('valid IP') do |req|
|
||||
req.remote_ip == "127.0.0.1"
|
||||
end
|
||||
end
|
||||
|
||||
allow_ok_requests
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue