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.



109
110
111
# File 'lib/sniffer/data_item.rb', line 109

def body
  @body
end

#headersObject

Returns the value of attribute headers.



109
110
111
# File 'lib/sniffer/data_item.rb', line 109

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



109
110
111
# File 'lib/sniffer/data_item.rb', line 109

def status
  @status
end

#timingObject

Returns the value of attribute timing.



109
110
111
# File 'lib/sniffer/data_item.rb', line 109

def timing
  @timing
end

Instance Method Details

#to_hObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/sniffer/data_item.rb', line 111

def to_h
  {
    status: status,
    headers: headers,
    body: # frozen_string_literal: true
# Sniffer data item stores a request info
# Basic object for request and response objects
# Stores http request data
# rubocop:enable
# Stores http response data

body&.to_s,
    timing: timing
  }
end

#to_logObject

rubocop:disable Metrics/AbcSize



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/sniffer/data_item.rb', line 128

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