Class: Sniffer::DataItem::Response

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

Overview

Stores http response 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.



91
92
93
# File 'lib/sniffer/data_item.rb', line 91

def body
  @body
end

#headersObject

Returns the value of attribute headers.



91
92
93
# File 'lib/sniffer/data_item.rb', line 91

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



91
92
93
# File 'lib/sniffer/data_item.rb', line 91

def status
  @status
end

#timingObject

Returns the value of attribute timing.



91
92
93
# File 'lib/sniffer/data_item.rb', line 91

def timing
  @timing
end

Instance Method Details

#to_hObject



93
94
95
96
97
98
99
100
# File 'lib/sniffer/data_item.rb', line 93

def to_h
  {
    status: status,
    headers: headers,
    body: body && body.to_s,
    timing: timing
  }
end

#to_logObject

rubocop:disable Metrics/AbcSize



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sniffer/data_item.rb', line 103

def to_log
  {}.tap do |hash|
    hash[:status] = status if log_settings["response_status"]

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

    hash[:timing] = timing if log_settings["timing"]
    hash[:response_body] = body.to_s if log_settings["response_body"]
  end
end