Ethan-Zhang-ZH commented on issue #13179: URL: https://github.com/apache/apisix/issues/13179#issuecomment-4341466935
> [@niemne](https://github.com/niemne) Thanks for the detailed proposal! The overall direction looks good and references the right PRs. A few adjustments are needed though: > > 1. **Remove `header_prefix`**: Unlike `limit-count` which sets `X-RateLimit-*` response headers, `limit-req` does not set any rate-limiting response headers currently. So `header_prefix` has no practical effect here. If we want to add response headers for `limit-req` in the future, it should be a separate enhancement. > 2. **Remove `key_type` from rules**: Following the pattern of `limit-conn` and `limit-count` rules implementation (see `apisix/plugins/limit-conn/init.lua:64-98`), the `key` in rules is always resolved as a variable combination via `core.utils.resolve_var`. If no variables are resolved (`n_resolved == 0`), the rule is skipped. There's no need for a `key_type` field in rules. > > The rest of the proposal looks good: > > * `oneOf` variable support for `rate`/`burst` > * `oneOf` schema ensuring legacy and rules modes are mutually exclusive > * Removing `lrucache.plugin_ctx` in favor of per-request limiter creation > > Please update the proposal with the above adjustments and start the implementation. I'd also suggest extracting the core logic into `apisix/plugins/limit-req/init.lua` to keep the directory structure consistent with `limit-conn`. I’d like to propose that we keep key_type and support the constant value in the rules for limit-req. The main use case is: when the same route serves multiple endpoints (e.g. /api/v1/users and /api/v1/orders), we often want different rate limits for each endpoint without defining separate routes. By allowing key_type: "constant" and a static key, each rule can define a fixed, unchanging key that represents a specific interface or group. For example: ``` rules: - key: "users_api" key_type: "constant" rate: 10 burst: 0 _meta: filter: [["uri", "==", "/api/v1/users"]] - key: "orders_api" key_type: "constant" rate: 5 burst: 0 _meta: filter: [["uri", "==", "/api/v1/orders"]] ``` This makes the config intuitive and avoids coupling the rate limit key to dynamic variables when the intention is simply “a limit for that interface”. Without constant, users would have to coerce a variable like $uri or misuse $host even when the limit target is fixed. What do you think? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
