Class: HttpEventLogger::Event::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/http_event_logger/event/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Response

Returns a new instance of Response.


10
11
12
13
14
15
16
17
# File 'lib/http_event_logger/event/response.rb', line 10

def initialize(args)
  @request               = args[:request]
  @time_taken_in_seconds = args[:time_taken_in_seconds]
  @status                = args[:status].to_s
  @headers               = HttpEventLogger::Event::Headers.new(args[:headers])
  @raw_body              = args[:body]
  HttpEventLogger::Event::Observer.observe(:received, self)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers


6
7
8
# File 'lib/http_event_logger/event/response.rb', line 6

def headers
  @headers
end

#requestObject (readonly)

Returns the value of attribute request


6
7
8
# File 'lib/http_event_logger/event/response.rb', line 6

def request
  @request
end

#statusObject (readonly)

Returns the value of attribute status


6
7
8
# File 'lib/http_event_logger/event/response.rb', line 6

def status
  @status
end

#time_taken_in_secondsObject (readonly)

Returns the value of attribute time_taken_in_seconds


6
7
8
# File 'lib/http_event_logger/event/response.rb', line 6

def time_taken_in_seconds
  @time_taken_in_seconds
end

Instance Method Details

#bodyObject


19
20
21
22
23
24
25
26
27
# File 'lib/http_event_logger/event/response.rb', line 19

def body
  if body_read_deferred?
    "[not available]"
  elsif body_gzip_encoded?
    Zlib::GzipReader.new(StringIO.new(@raw_body.to_s)).read
  else
    @raw_body.to_s
  end
end

#body_with_formattingObject


29
30
31
# File 'lib/http_event_logger/event/response.rb', line 29

def body_with_formatting
  body.include?("\n") ? "\n#{body}" : body
end