Class: Wafris::WafrisRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/wafris/wafris_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, env) ⇒ WafrisRequest

Returns a new instance of WafrisRequest.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/wafris/wafris_request.rb', line 8

def initialize(request, env)
  @ip = encode_to_utf8(IpResolver.new(request).resolve)
  @user_agent = encode_to_utf8(request.user_agent)
  @path = encode_to_utf8(request.path)
  @parameters = encode_to_utf8(Rack::Utils.build_query(request.params))
  @host = encode_to_utf8(request.host.to_s)
  @method = encode_to_utf8(request.request_method)
  @headers = extract_headers(env)
  @request_id = env.fetch("action_dispatch.request_id", SecureRandom.uuid.to_s)
  @request_timestamp = Time.now.utc.to_i
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def headers
  @headers
end

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def host
  @host
end

#ipObject (readonly)

Returns the value of attribute ip.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def ip
  @ip
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def method
  @method
end

#parametersObject (readonly)

Returns the value of attribute parameters.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def parameters
  @parameters
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def path
  @path
end

#request_idObject (readonly)

Returns the value of attribute request_id.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def request_id
  @request_id
end

#request_timestampObject (readonly)

Returns the value of attribute request_timestamp.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def request_timestamp
  @request_timestamp
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



5
6
7
# File 'lib/wafris/wafris_request.rb', line 5

def user_agent
  @user_agent
end

Instance Method Details

#data(treatment:, category:, rule:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wafris/wafris_request.rb', line 20

def data(treatment:, category:, rule:)
  {
    ip: @ip,
    user_agent: @user_agent,
    path: @path,
    parameter: @parameters,
    host: @host,
    method: @method,
    request_id: @request_id,
    timestamp: @request_timestamp,
    treatment: treatment,
    category: category,
    rule: rule
  }
end