45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/better-faraday.rb', line 45
def describe
= env..deep_dup
request_json = parse_json(env.request_body)
= ::Hash === env. ? env..deep_dup : {}
response_json = parse_json(env.body)
[, request_json, , response_json].compact.each(&method(:protect!))
[ "",
"-- #{status} #{reason_phrase} --",
"",
"-- Request URL --",
env.url.to_s,
"",
"-- Request method --",
env.method.to_s.upcase,
"",
"-- Request headers --",
::JSON.generate().yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
"",
"-- Request body --",
(request_json ? ::JSON.generate(request_json) : env.request_body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
"",
"-- Response headers --",
( ? ::JSON.generate() : env..to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
"",
"-- Response body --",
(response_json ? ::JSON.generate(response_json) : env.body.to_s).yield_self { |t| t.truncate(1024, omission: "... (truncated, full length: #{t.length})") },
""
].join("\n")
end
|