mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Improve documentation of Rack::Attack::Request
https://github.com/kickstarter/rack-attack/issues/73
This commit is contained in:
parent
66231dc5b2
commit
5c78f84be2
2 changed files with 18 additions and 1 deletions
|
|
@ -57,7 +57,7 @@ The algorithm is actually more concise in code: See [Rack::Attack.call](https://
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
def call(env)
|
def call(env)
|
||||||
req = Rack::Request.new(env)
|
req = Rack::Attack::Request.new(env)
|
||||||
|
|
||||||
if whitelisted?(req)
|
if whitelisted?(req)
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
@ -72,6 +72,10 @@ def call(env)
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note: `Rack::Attack::Request` is just a subclass of `Rack::Attack` so that you
|
||||||
|
can cleanly [monkey patch helper methods] onto the
|
||||||
|
[request object](https://github.com/kickstarter/rack-attack/blob/master/lib/rack/attack/request.rb).
|
||||||
|
|
||||||
## About Tracks
|
## About Tracks
|
||||||
|
|
||||||
`Rack::Attack.track` doesn't affect request processing. Tracks are an easy way to log and measure requests matching arbitrary attributes.
|
`Rack::Attack.track` doesn't affect request processing. Tracks are an easy way to log and measure requests matching arbitrary attributes.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,16 @@
|
||||||
|
# Rack::Attack::Request is the same as ::Rack::Request by default.
|
||||||
|
#
|
||||||
|
# This is a safe place to add custom helper methods to the request object
|
||||||
|
# through monkey patching:
|
||||||
|
#
|
||||||
|
# class Rack::Attack::Request < ::Rack::Request
|
||||||
|
# def localhost?
|
||||||
|
# ip == "127.0.0.1"
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# Rack::Attack.whitelist("localhost") {|req| req.localhost? }
|
||||||
|
#
|
||||||
module Rack
|
module Rack
|
||||||
class Attack
|
class Attack
|
||||||
class Request < ::Rack::Request
|
class Request < ::Rack::Request
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue