lib/rack/throttle/limiters/limiter.rb in improved-rack-throttle-0.7.1 vs lib/rack/throttle/limiters/limiter.rb in improved-rack-throttle-0.8.0
- old
+ new
@@ -21,11 +21,10 @@
# @option options [Integer] :code (403)
# @option options [String] :message ("Rate Limit Exceeded")
def initialize(app, options = {})
rules = options.delete(:rules) || {}
@app, @options, @matchers = app, options, []
- @matchers += Array(rules[:ip]).map { |rule| IpMatcher.new(rule) } if rules[:ip]
@matchers += Array(rules[:url]).map { |rule| UrlMatcher.new(rule) } if rules[:url]
@matchers += Array(rules[:user_agent]).map { |rule| UserAgentMatcher.new(rule) } if rules[:user_agent]
@matchers += Array(rules[:method]).map { |rule| MethodMatcher.new(rule) } if rules[:method]
end
@@ -195,10 +194,11 @@
##
# Outputs a `Rate Limit Exceeded` error.
#
# @return [Array(Integer, Hash, #each)]
def rate_limit_exceeded
- headers = respond_to?(:retry_after) ? {'Retry-After' => retry_after.to_f.ceil.to_s} : {}
+ return_retry_after = options[:return_retry_after] || false
+ headers = (respond_to?(:retry_after) && return_retry_after) ? {'Retry-After' => retry_after.to_f.ceil.to_s} : {}
http_error(options[:code] || 403, options[:message] || 'Rate Limit Exceeded', headers)
end
##
# Outputs an HTTP `4xx` or `5xx` response.