【发布时间】:2013-03-03 00:39:29
【问题描述】:
我正在阅读有关 Rack::Throttle 的信息,我想将默认客户端标识符从 IP 更改为其他内容。文档说可以做到
Rack::Throttle 存储和维护的限速计数器是 键控到唯一的 HTTP 客户端。
默认情况下,HTTP 客户端由其 IP 地址唯一标识 由 Rack::Request#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
【问题讨论】:
标签: ruby heroku rubygems rack throttling