Class: Sniffer::DataItem::Request

Inherits:
HttpObject show all
Defined in:
lib/sniffer/data_item.rb

Overview

Stores http request data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HttpObject

#log_message, #log_settings

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def body
  @body
end

#headersObject

Returns the value of attribute headers.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def host
  @host
end

#methodObject

Returns the value of attribute method.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def method
  @method
end

#portObject

Returns the value of attribute port.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def port
  @port
end

#queryObject

Returns the value of attribute query.



47
48
49
# File 'lib/sniffer/data_item.rb', line 47

def query
  @query
end

Instance Method Details

#to_hObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/sniffer/data_item.rb', line 49

def to_h
  {
    host: host,
    query: query,
    port: port,
    headers: headers,
    body: body,
    method: method
  }
end

#to_logObject

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sniffer/data_item.rb', line 61

def to_log
  {}.tap do |hash|
    if log_settings["request_url"]
      hash[:port] = port
      hash[:host] = host
      hash[:query] = query
    end

    if log_settings["request_headers"]
      headers.each do |(k, v)|
        hash[:"rq_#{k.to_s.tr("-", '_').downcase}"] = v
      end
    end

    hash[:method] = method if log_settings["request_method"]
    hash[:request_body] = body if log_settings["request_body"]
  end
end