class Datadome::Inquirer
Attributes
exclude_matchers[R]
include_matchers[R]
Public Class Methods
new(env, exclude_matchers: nil, include_matchers: nil)
click to toggle source
# File lib/datadome/inquirer.rb, line 8 def initialize(env, exclude_matchers: nil, include_matchers: nil) @env = env @exclude_matchers = exclude_matchers || Datadome.configuration.exclude_matchers @include_matchers = include_matchers || Datadome.configuration.include_matchers end
Public Instance Methods
build_response()
click to toggle source
# File lib/datadome/inquirer.rb, line 15 def build_response @validation_response.to_rack_response end
enriching() { || ... }
click to toggle source
# File lib/datadome/inquirer.rb, line 19 def enriching status, headers, response = yield added_headers = ::Rack::Utils::HeaderHash.new(@validation_response.response_headers) headers = ::Rack::Utils::HeaderHash.new(headers) existing_set_cookie = headers["Set-Cookie"] headers.merge!(added_headers) if added_headers["Set-Cookie"] && existing_set_cookie headers["Set-Cookie"] = merge_cookie(existing_set_cookie, added_headers["Set-Cookie"]) end [status, headers, response] end
ignore?()
click to toggle source
# File lib/datadome/inquirer.rb, line 36 def ignore? return false if include_matchers.empty? && exclude_matchers.empty? request = ::Rack::Request.new(@env) if include_matchers.any? any_include_matches = include_matchers.any? do |matcher| matcher.call(request.host, request.path) end return true unless any_include_matches end if exclude_matchers.any? any_exclude_matches = exclude_matchers.any? do |matcher| matcher.call(request.host, request.path) end return true if any_exclude_matches end false end
inquire()
click to toggle source
# File lib/datadome/inquirer.rb, line 66 def inquire @validation_response = validate_request end
intercept?()
click to toggle source
# File lib/datadome/inquirer.rb, line 62 def intercept? @validation_response.pass == false || @validation_response.redirect end
Private Instance Methods
validate_request()
click to toggle source
# File lib/datadome/inquirer.rb, line 74 def validate_request validation_request = ValidationRequest.from_env(@env) Datadome.logger.debug("Datadome: Validation Request: #{validation_request.inspect}") client = Client.new client.validate_request(validation_request.to_api_params).tap do |validation_response| Datadome.logger.debug("Datadome: Validation Response: #{validation_response.inspect}") end end