I use rack-throttlerails 3 as a mechanism for speed limiting. I created my own class based on it Rack::Throttle::Intervalto define custom speed limiting logic. I check if the request is being executed for precise control and precise action. This works fine if I make a request GET. However, if I send a request POST, I get some problems.
class CustomLimiter < Rack::Throttle::Interval
def allowed?(request)
path_info = Rails.application.routes.recognize_path request.url rescue path_info = {}
if path_info[:controller] == "some_controller" and path_info[:action] == "some_action"
super
else
true
end
end
end
Here are my actions with the controller
def question
end
def check_answer
redirect_to question_path
end
My routes
get "questions" => "application#question", :as => "question"
post "check_answer" => "application#check_answer", :as => "check_answer"
EDIT:
, POST , allowed?. Rails.application.routes.recognize_path, Route set not finalized. rack-throttle
application.rb
class Application < Rails::Application
config.require "ip_limiter"
config.require "ip_user_agent_limiter"
config.middleware.use IpLimiter, :min => 0.2
config.middleware.use IpUserAgentLimiter, :min => 2
end
IpLimiter IpUserAgentLimiter