我正在阅读有关Rack :: Throttle,我想将默认客户端标识符从IP更改为其他某些。该文件说可以完成子类Rack :: Throttle
由Rack :: Throttle存储和维护的限速计数器是 键入唯一的HTTP客户端。
默认情况下,HTTP客户端由Rack :: Request#ip返回的IP地址 唯一标识。如果您希望改为使用更详细的特定于应用程序的标识符(例如会话密钥或 用户帐户名称),则只需实施限制策略的子类 实施并覆盖#client_identifier方法。
我不知道在哪里添加,在这里是我目前的另一种方法的子类。有人知道怎么做这个吗? https://github.com/datagraph/rack-throttle
module Rack
module Throttle
class DailyRequests < Daily
def allowed?(request)
## Insert rules
super request
end
end
class HourlyRequests < Hourly
def allowed?(request)
## Insert rules
super request
end
end
class RequestInterval < Interval
def allowed?(request)
## Insert rules
super request
end
end
end
end
[覆盖client_identifier方法](https://github.com/datagraph/rack-throttle/blob/master/lib/rack/throttle/limiter.rb#L157),我想。 – Zabba 2013-03-03 05:49:29