Browse files

Added an option for configuring the HTTP status code used (defaulting…

… to '403 Forbidden').
  • Loading branch information...
1 parent 8be3543 commit 1c0be1670bc1e75360d7926080c94068fe235648 @bendiken bendiken committed Mar 21, 2010
Showing with 10 additions and 15 deletions.
  1. +10 −15 lib/rack/throttle/limiter.rb
View
25 lib/rack/throttle/limiter.rb
@@ -8,10 +8,11 @@ class Limiter
##
# @param [#call] app
# @param [Hash{Symbol => Object}] options
- # @option options [String] :cache (Hash.new)
- # @option options [String] :key (nil)
- # @option options [String] :key_prefix (nil)
- # @option options [String] :message ("Rate Limit Exceeded")
+ # @option options [String] :cache (Hash.new)
+ # @option options [String] :key (nil)
+ # @option options [String] :key_prefix (nil)
+ # @option options [Integer] :code (403)
+ # @option options [String] :message ("Rate Limit Exceeded")
def initialize(app, options = {})
@app, @options = app, options
end
@@ -155,18 +156,12 @@ def request_start_time(request)
##
# Outputs a `Rate Limit Exceeded` error.
#
+ # @param [Integer] code
+ # @param [String] message
# @return [Array(Integer, Hash, #each)]
- def rate_limit_exceeded
- forbidden(options[:message] || 'Rate Limit Exceeded')
- end
-
- ##
- # Outputs an HTTP `403 Forbidden` response.
- #
- # @param [String, #to_s] message
- # @return [Array(Integer, Hash, #each)]
- def forbidden(message = nil)
- http_error(403, message)
+ def rate_limit_exceeded(code = nil, message = nil)
+ http_error(code || options[:code] || 403,
+ message || options[:message] || 'Rate Limit Exceeded')
end
##

0 comments on commit 1c0be16

Please sign in to comment.