8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/rack/dev_insight/recorder/api_recorder.rb', line 8
def record(net_http:, request:)
return yield if Context.current.nil?
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
response = yield
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
Context.current.result.add_api(
method: request.method,
url: request.uri || "#{net_http.address}:#{net_http.port}#{request.path}",
request_headers: request..map { |field, value| Result.(field, value) },
request_body: request.body,
status: response.code.to_i,
response_headers: response..map { |field, value| Result.(field, value) },
response_body: response.body,
backtrace: get_backtrace,
duration: format('%.2f', duration * 1000).to_f,
)
response
end
|