Class: Tassadar::Server::Throttle

Inherits:
Rack::Throttle::Hourly
  • Object
show all
Defined in:
lib/tassadar/server/throttle.rb

Instance Method Summary collapse

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



19
20
21
22
23
24
# File 'lib/tassadar/server/throttle.rb', line 19

def http_error(code, message = nil, headers = {})
  [ code,
    { 'Content-Type' => 'text/plain; charset=utf-8' }.merge(headers),
    Array( http_status(code) + (message.nil? ? "\n" : " (#{message})\n") )
  ]
end