We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
my web application has two parts, one for web, one for api.
I want to different interval rate-limiting for the them
api : use Rack::Throttle::Hourly, :max => 100 # requests web : use Rack::Throttle::Interval, :min => 1.0 # seconds
use Rack::Throttle::Hourly, :max => 100 # requests
use Rack::Throttle::Interval, :min => 1.0 # seconds
The text was updated successfully, but these errors were encountered:
You can create some custom middleware to do so. For example (untested, though I've used something similar):
# app/middleware/throttlers.rb module ThrottleHelper def path_starts_with?(path) path_info = (Rails.application.routes.recognize_path request.url rescue {}) || {} !path_info[:controller].nil? && path_info[:controller].start_with?(path) end end class ApiHourlyThrottler < Rack::Throttle::Hourly include ThrottleHelper def allowed?(request) if path_starts_with?('/api') super else true end end end class WebIntervalThrottler < Rack::Throttle::Interval include ThrottleHelper def allowed?(request) if !path_starts_with?('/api') super else true end end end
Then in application.rb
application.rb
config.middleware.use 'ApiHourlyThrottler', max: 100, ... config.middleware.use 'WebIntervalThrottler', min: 1.0, ...
Plenty you can do to make this suit your needs: matching on controllers, throttling only certain routes etc.
Sorry, something went wrong.
@OscarBarrett has the correct approach. It seems you are looking to add middleware based on the path, which I do not believe is possible.
No branches or pull requests
my web application has two parts, one for web, one for api.
I want to different interval rate-limiting for the them
api :
use Rack::Throttle::Hourly, :max => 100 # requests
web :
use Rack::Throttle::Interval, :min => 1.0 # seconds
The text was updated successfully, but these errors were encountered: