4 * Pick out useful got response fields.
5 * @param {GotResponse} res
8 const gotResponseLogData
= (res
) => {
9 const data
= pick(res
, [
17 if (typeof res
.body
=== 'string') {
18 data
.body
= logTruncate(data
.body
, 100);
19 } else if (res
.body
instanceof Buffer
) {
20 data
.body
= `<Buffer ${res.body.byteLength} bytes>`;
22 data
.elapsedTimeMs
= res
?.timings
?.phases
?.total
;
23 if (res
?.redirectUrls
?.length
) {
24 data
.redirectUrls
= res
.redirectUrls
;
26 if (res
?.retryCount
) {
27 data
.retryCount
= res
.retryCount
;
34 * Limit length of string to keep logs sane
39 const logTruncate
= (str
, len
) => {
40 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
43 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
48 * Return a new object with selected props.
50 * @param {String[]} props
52 const pick
= (obj
, props
) => {
53 return props
.reduce((acc
, prop
) => {
55 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection
63 * Return a set containing non-shared items between two sets.
68 const setSymmetricDifference
= (a
, b
) => {
82 * URL objects have weird names.
83 * @param {String} component
86 const properURLComponentName
= (component
) => {
87 // eslint-disable-next-line security/detect-object-injection
91 }[component
] || component
;
99 setSymmetricDifference
,
100 properURLComponentName
,