class Readme::Har::RequestSerializer
Public Class Methods
new(request, filter = Filter::None.new)
click to toggle source
# File lib/readme/har/request_serializer.rb, line 7 def initialize(request, filter = Filter::None.new) @request = request @filter = filter end
Public Instance Methods
as_json()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 12 def as_json { method: @request.request_method, queryString: Har::Collection.new(@filter, @request.query_params).to_a, url: @request.url, httpVersion: @request.http_version, headers: Har::Collection.new(@filter, @request.headers).to_a, cookies: Har::Collection.new(@filter, @request.cookies).to_a, postData: postData, headersSize: -1, bodySize: @request.content_length }.compact end
Private Instance Methods
form_encoded_body()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 44 def form_encoded_body Har::Collection.new(@filter, @request.parsed_form_data).to_a end
json_body()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 58 def json_body parsed_body = JSON.parse(@request.body) Har::Collection.new(@filter, parsed_body).to_h.to_json end
pass_through_body()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 63 def pass_through_body @request.body end
postData()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 28 def postData if @request.content_type.nil? nil elsif @request.form_data? { params: form_encoded_body, mimeType: @request.content_type } else { text: request_body, mimeType: @request.content_type } end end
request_body()
click to toggle source
# File lib/readme/har/request_serializer.rb, line 48 def request_body if @filter.pass_through? pass_through_body else # Only JSON allowed for non-pass-through situations. It will raise # if the body can't be parsed as JSON, aborting the request. json_body end end