Skip to content

Conversation

@franzliedke
Copy link

So far, the documentation is suggesting 100% global configuration for what's essentially a middleware. I do wonder whether there are any reasons not to support passing in a configuration directly wherever I am adding a middleware to my stack. (This could be a base controller with per-controller middleware.)

Pseudo-code example:

config = Rack::Attack::Configuration.new.tap do
  _1.throttle("my_api.throttle_per_minute", limit: 20,  period: 1.minute, &:ip)
  _1.throttle("my_api.throttle_per_hour",   limit: 100, period: 1.hour,   &:ip)
end

use Rack::Attack, config

Primarily, this would let me avoid mixing filters (for request type and path) with the discriminator block - I'd rather keep the filtering to my middleware builder.

Let me know what you think about this idea, and especially what may speak against this. Then I'm happy to send a "real" pull request with tests etc.

@santib
Copy link
Collaborator

santib commented Jan 10, 2024

Hi @franzliedke I think this one would be solved by #442 , right?

@franzliedke
Copy link
Author

@santib Yes, totally! Looks like I only got through the first half of the PR list. 😇

@franzliedke franzliedke deleted the patch-1 branch January 10, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants