Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… to '403 Forbidden').
  • Loading branch information...
commit 1c0be1670bc1e75360d7926080c94068fe235648 1 parent 8be3543
Arto Bendiken bendiken authored

Showing 1 changed file with 10 additions and 15 deletions. Show diff stats Hide diff stats

  1. +10 15 lib/rack/throttle/limiter.rb
25 lib/rack/throttle/limiter.rb
@@ -8,10 +8,11 @@ class Limiter
8 8 ##
9 9 # @param [#call] app
10 10 # @param [Hash{Symbol => Object}] options
11   - # @option options [String] :cache (Hash.new)
12   - # @option options [String] :key (nil)
13   - # @option options [String] :key_prefix (nil)
14   - # @option options [String] :message ("Rate Limit Exceeded")
  11 + # @option options [String] :cache (Hash.new)
  12 + # @option options [String] :key (nil)
  13 + # @option options [String] :key_prefix (nil)
  14 + # @option options [Integer] :code (403)
  15 + # @option options [String] :message ("Rate Limit Exceeded")
15 16 def initialize(app, options = {})
16 17 @app, @options = app, options
17 18 end
@@ -155,18 +156,12 @@ def request_start_time(request)
155 156 ##
156 157 # Outputs a `Rate Limit Exceeded` error.
157 158 #
  159 + # @param [Integer] code
  160 + # @param [String] message
158 161 # @return [Array(Integer, Hash, #each)]
159   - def rate_limit_exceeded
160   - forbidden(options[:message] || 'Rate Limit Exceeded')
161   - end
162   -
163   - ##
164   - # Outputs an HTTP `403 Forbidden` response.
165   - #
166   - # @param [String, #to_s] message
167   - # @return [Array(Integer, Hash, #each)]
168   - def forbidden(message = nil)
169   - http_error(403, message)
  162 + def rate_limit_exceeded(code = nil, message = nil)
  163 + http_error(code || options[:code] || 403,
  164 + message || options[:message] || 'Rate Limit Exceeded')
170 165 end
171 166
172 167 ##

0 comments on commit 1c0be16

Please sign in to comment.
Something went wrong with that request. Please try again.