mirror of
https://github.com/samsonjs/rack-attack.git
synced 2026-04-27 15:07:41 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
c8abad53fe
2 changed files with 23 additions and 7 deletions
|
|
@ -18,7 +18,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Changed `ActiveSupport::Notifications` event naming to comply with the recommneded format.
|
- Changed `ActiveSupport::Notifications` event naming to comply with the recommended format.
|
||||||
- Changed `ActiveSupport::Notifications` event so that the 5th yielded argument to the `#subscribe` method is now a
|
- Changed `ActiveSupport::Notifications` event so that the 5th yielded argument to the `#subscribe` method is now a
|
||||||
`Hash` instead of a `Rack::Attack::Request`, to comply with `ActiveSupport`s spec. The original request object is
|
`Hash` instead of a `Rack::Attack::Request`, to comply with `ActiveSupport`s spec. The original request object is
|
||||||
still accessible, being the value of the hash's `:request` key.
|
still accessible, being the value of the hash's `:request` key.
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,33 @@ module Rack
|
||||||
#
|
#
|
||||||
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
# So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize
|
||||||
# the counter. After that we continue using the original RedisCacheStore#increment.
|
# the counter. After that we continue using the original RedisCacheStore#increment.
|
||||||
if options[:expires_in] && !read(name)
|
rescuing do
|
||||||
write(name, amount, options)
|
if options[:expires_in] && !read(name)
|
||||||
|
write(name, amount, options)
|
||||||
|
|
||||||
amount
|
amount
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read(*_args)
|
||||||
|
rescuing { super }
|
||||||
|
end
|
||||||
|
|
||||||
def write(name, value, options = {})
|
def write(name, value, options = {})
|
||||||
super(name, value, options.merge!(raw: true))
|
rescuing do
|
||||||
|
super(name, value, options.merge!(raw: true))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def rescuing
|
||||||
|
yield
|
||||||
|
rescue Redis::BaseError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue