6ede0a80fde15d00e7de72edfaae252bedf1bec8
4 * @typedef {object} GotResponse
5 * @property {Buffer|string} body response body
6 * @property {Array} redirectUrls followed redirect urls
7 * @property {number=} retryCount retries
8 * @property {object=} timings timings object
9 * @property {object=} timings.phases timing phases object
10 * @property {number=} timings.phases.total timing total ms
13 * Pick out useful got response fields.
14 * @param {GotResponse} res response
15 * @returns {object} filtered response
17 const gotResponseLogData
= (res
) => {
18 const data
= pick(res
, [
26 if (typeof res
.body
=== 'string') {
27 data
.body
= logTruncate(data
.body
, 100);
28 } else if (res
.body
instanceof Buffer
) {
29 data
.body
= `<Buffer ${res.body.byteLength} bytes>`;
31 data
.elapsedTimeMs
= res
?.timings
?.phases
?.total
;
32 if (res
?.redirectUrls
?.length
) {
33 data
.redirectUrls
= res
.redirectUrls
;
35 if (res
?.retryCount
) {
36 data
.retryCount
= res
.retryCount
;
43 * Limit length of string to keep logs sane
44 * @param {string} str string
45 * @param {number} len length
46 * @returns {string} truncated string
48 const logTruncate
= (str
, len
) => {
49 if (typeof str
!== 'string' || str
.toString().length
<= len
) {
52 return str
.toString().slice(0, len
) + `... (${str.toString().length} bytes)`;
57 * Return a new object with selected props.
58 * @param {object} obj object
59 * @param {string[]} props list of properties
60 * @returns {object} filtered object
62 const pick
= (obj
, props
) => {
63 return props
.reduce((acc
, prop
) => {
65 acc
[prop
] = obj
[prop
]; // eslint-disable-line security/detect-object-injection
73 * Return a set containing non-shared items between two sets.
74 * @param {Set} a set a
75 * @param {Set} b set b
76 * @returns {Set} set difference
78 const setSymmetricDifference
= (a
, b
) => {
92 * URL objects have weird names.
93 * @param {string} component url component name
94 * @returns {string} translated url component name
96 const properURLComponentName
= (component
) => {
97 // eslint-disable-next-line security/detect-object-injection
101 }[component
] || component
;
109 setSymmetricDifference
,
110 properURLComponentName
,