Class: Tassadar::Server::Throttle
- Inherits:
-
Rack::Throttle::Hourly
- Object
- Rack::Throttle::Hourly
- Tassadar::Server::Throttle
- Defined in:
- lib/tassadar/server/throttle.rb
Instance Method Summary collapse
- #client_identifier(request) ⇒ Object
-
#http_error(code, message = nil, headers = {}) ⇒ Object
Patch for unmerged github.com/datagraph/rack-throttle/pull/6.
Instance Method Details
#client_identifier(request) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/tassadar/server/throttle.rb', line 7 def client_identifier(request) # Determine whether the user should be identified by a unique # header (for example, a username or token), or simply by IP # for the purpose of rate limiting. if ENV['USER_HEADER'] && request.env.has_key?(ENV['USER_HEADER']) request.env[ENV['USER_HEADER']].to_s else request.ip.to_s end end |
#http_error(code, message = nil, headers = {}) ⇒ Object
Patch for unmerged github.com/datagraph/rack-throttle/pull/6
19 20 21 22 23 24 |
# File 'lib/tassadar/server/throttle.rb', line 19 def http_error(code, = nil, headers = {}) [ code, { 'Content-Type' => 'text/plain; charset=utf-8' }.merge(headers), Array( http_status(code) + (.nil? ? "\n" : " (#{})\n") ) ] end |