Yii2 RateLimiter header X-Rate-Limit-Reset 有错误的值

Yii2 RateLimiter header X-Rate-Limit-Reset has wrong value

我一直在努力理解 Yii2 在 this line.

中计算的 X-Rate-Limit-Reset header 值背后的逻辑

documentation 状态:

X-Rate-Limit-Reset, the number of seconds to wait in order to get the maximum number of allowed requests

所以,如果速率限制是 100,时间 period/window 是 3600 秒,那么我理解它应该像这样工作:

我是不是误会了什么?或者这是一个错误?

其实应该是这样的

  • 在 10:00 returns 和 header X-Rate-Limit-Reset 36
  • 请求 #1
  • 请求 #2 在 10:30 returns 和 header X-Rate-Limit-Reset 36
  • 在 10:59 returns header X-Rate-Limit-Reset 36
  • 请求 #3

这是因为在速率限制 100 / 3600 和稳定的请求数速率下,需要一百个 36 秒的间隔来填充给定的 window (3600) 所以在第一个请求 36 秒后你又得到了您可以使用 100 个请求。

不幸的是 bug with this feature in Yii 2 (it returns 0 every time) but because of your question I was able to find it and propose a fix 应该在 2.0.14 中发布。