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

#body=(value) ⇒ Object (writeonly)

Sets the attribute body

Parameters:

  • value

    the value to set the attribute body to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def body=(value)
  @body = value
end

#headers=(value) ⇒ Object (writeonly)

Sets the attribute headers

Parameters:

  • value

    the value to set the attribute headers to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def headers=(value)
  @headers = value
end

#host=(value) ⇒ Object (writeonly)

Sets the attribute host

Parameters:

  • value

    the value to set the attribute host to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def host=(value)
  @host = value
end

#method=(value) ⇒ Object (writeonly)

Sets the attribute method

Parameters:

  • value

    the value to set the attribute method to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def method=(value)
  @method = value
end

#port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def port=(value)
  @port = value
end

#query=(value) ⇒ Object (writeonly)

Sets the attribute query

Parameters:

  • value

    the value to set the attribute query to.



62
63
64
# File 'lib/sniffer/data_item.rb', line 62

def query=(value)
  @query = value
end

Instance Method Details

#to_hObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/sniffer/data_item.rb', line 64

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

#to_logObject

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sniffer/data_item.rb', line 76

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