Class: Rack::Throttle::UserAgentMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/rack/throttle/matchers/user_agent_matcher.rb

Overview

User Agent Matchers are used to restrict requests based on the User Agent supplied by the requester. For instance, you may care about limiting a specific API consumer who reliably uses a known User-Agent. UserAgentMatchers take Regexp objects to match against the User-Agent.

Instance Attribute Summary

Attributes inherited from Matcher

#rule

Instance Method Summary collapse

Methods inherited from Matcher

#initialize

Constructor Details

This class inherits a constructor from Rack::Throttle::Matcher

Instance Method Details

#identifierString

Returns:

  • (String)


18
19
20
# File 'lib/rack/throttle/matchers/user_agent_matcher.rb', line 18

def identifier
  "ua-" + @rule.inspect
end

#match?(request) ⇒ Boolean

Parameters:

  • request (Rack::Request)

Returns:

  • (Boolean)


12
13
14
# File 'lib/rack/throttle/matchers/user_agent_matcher.rb', line 12

def match?(request)
  !!(@rule =~ request.user_agent)
end