Class: Datadome::Inquirer

Inherits:
Object
  • Object
show all
Defined in:
lib/datadome/inquirer.rb

Instance Method Summary collapse

Constructor Details

#initialize(env, exclude_matchers: nil, include_matchers: nil) ⇒ Inquirer

Returns a new instance of Inquirer.



8
9
10
11
12
13
# 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

Instance Method Details

#build_responseObject



15
16
17
# File 'lib/datadome/inquirer.rb', line 15

def build_response
  @validation_response.to_rack_response
end

#enrichingObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

#inquireObject



66
67
68
# File 'lib/datadome/inquirer.rb', line 66

def inquire
  @validation_response = validate_request
end

#intercept?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/datadome/inquirer.rb', line 62

def intercept?
  @validation_response.pass == false || @validation_response.redirect
end