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.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def body
  @body
end

#headersObject

Returns the value of attribute headers.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def host
  @host
end

#methodObject

Returns the value of attribute method.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def method
  @method
end

#portObject

Returns the value of attribute port.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def port
  @port
end

#queryObject

Returns the value of attribute query.



54
55
56
# File 'lib/sniffer/data_item.rb', line 54

def query
  @query
end

Instance Method Details

#to_hObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/sniffer/data_item.rb', line 56

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

#to_logObject

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sniffer/data_item.rb', line 68

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.to_s if log_settings["request_body"]
  end
end