Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use params to define identifier of throttle #14

Open
phuongnd08 opened this issue Mar 29, 2017 · 2 comments
Open

Can't use params to define identifier of throttle #14

phuongnd08 opened this issue Mar 29, 2017 · 2 comments
Labels

Comments

@phuongnd08
Copy link

thing like this no longer works with latest grape:
throttle max: 5, per: 1.day, identifier: Proc.new { params[:id] }
because params[:id] always return nil in a before filter.

@gottfrois
Copy link
Owner

oh that's a shame :( Unfortunately I am not using grape anymore in any of my projects so won't be able to maintain this gem for newest grape version without a little help from the community :)

@gottfrois gottfrois added the bug label Mar 29, 2017
@phuongnd08
Copy link
Author

I have no idea on how to fix this neither. End up adding a class like this:

class AttackLimiter
   def self.throttle(identifier, max:, per:)
      # counting and raising exception
   end
end

Then on the very top of a grape action

post :my_action do
  AttackLimiter.throttle "section", max: 10, per: 10.minutes
  # other logic here
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants