class Readme::Har::ResponseSerializer
Public Class Methods
new(request, response, filter)
click to toggle source
# File lib/readme/har/response_serializer.rb, line 7 def initialize(request, response, filter) @request = request @response = response @filter = filter end
Public Instance Methods
as_json()
click to toggle source
# File lib/readme/har/response_serializer.rb, line 13 def as_json { status: @response.status, statusText: Rack::Utils::HTTP_STATUS_CODES[@response.status], httpVersion: @request.http_version, headers: Har::Collection.new(@filter, @response.headers).to_a, content: content, redirectURL: @response.location.to_s, headersSize: -1, bodySize: @response.content_length, cookies: Har::Collection.new(@filter, @request.cookies).to_a } end
Private Instance Methods
content()
click to toggle source
# File lib/readme/har/response_serializer.rb, line 29 def content if @response.body.empty? empty_content elsif @response.json? json_content else pass_through_content end end
empty_content()
click to toggle source
# File lib/readme/har/response_serializer.rb, line 39 def empty_content {mimeType: "", size: 0} end
json_content()
click to toggle source
# File lib/readme/har/response_serializer.rb, line 43 def json_content parsed_body = JSON.parse(@response.body) { mimeType: @response.content_type, size: @response.content_length, text: Har::Collection.new(@filter, parsed_body).to_h.to_json } rescue pass_through_content end
pass_through_content()
click to toggle source
# File lib/readme/har/response_serializer.rb, line 55 def pass_through_content { mimeType: @response.content_type, size: @response.content_length, text: @response.body } end