@usebruno/js 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usebruno/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prepack": "npm run test"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@usebruno/common": "0.
|
|
19
|
+
"@usebruno/common": "0.9.0",
|
|
20
20
|
"@usebruno/crypto-js": "^3.1.9",
|
|
21
21
|
"@usebruno/query": "0.1.0",
|
|
22
22
|
"ajv": "^8.12.0",
|
package/src/bruno-response.js
CHANGED
|
@@ -51,6 +51,50 @@ class BrunoResponse {
|
|
|
51
51
|
this.res.data = clonedData;
|
|
52
52
|
this.body = clonedData;
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
// TODO: Refactor: dataBuffer size calculation should be handled in a shared utility so it can be passed and reused across the application
|
|
56
|
+
getSize() {
|
|
57
|
+
if (!this.res) {
|
|
58
|
+
return { header: 0, body: 0, total: 0 };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { data, dataBuffer, headers } = this.res;
|
|
62
|
+
let bodySize = 0;
|
|
63
|
+
|
|
64
|
+
// Use raw received bytes
|
|
65
|
+
if (Buffer.isBuffer(dataBuffer)) {
|
|
66
|
+
bodySize = dataBuffer.length;
|
|
67
|
+
} else {
|
|
68
|
+
// Use server-reported Content-Length
|
|
69
|
+
const contentLength = headers && (headers['content-length'] || headers['Content-Length']);
|
|
70
|
+
if (contentLength && !isNaN(contentLength)) {
|
|
71
|
+
bodySize = parseInt(contentLength, 10);
|
|
72
|
+
} else if (data != null) {
|
|
73
|
+
// Manual calculation
|
|
74
|
+
const raw = typeof data === 'string' ? data : JSON.stringify(data);
|
|
75
|
+
bodySize = Buffer.byteLength(raw);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const headerLines = [
|
|
80
|
+
`HTTP/1.1 ${this.res.status} ${this.res.statusText}`,
|
|
81
|
+
...Object.entries(this.res.headers || {}).flatMap(([key, value]) =>
|
|
82
|
+
Array.isArray(value)
|
|
83
|
+
? value.map((v) => `${key}: ${v}`)
|
|
84
|
+
: [`${key}: ${value}`]
|
|
85
|
+
),
|
|
86
|
+
'',
|
|
87
|
+
''
|
|
88
|
+
];
|
|
89
|
+
const headerSize = Buffer.byteLength(headerLines.join('\r\n'));
|
|
90
|
+
|
|
91
|
+
return { header: headerSize, body: bodySize, total: headerSize + bodySize };
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getDataBuffer() {
|
|
96
|
+
return this.res ? this.res.dataBuffer : null;
|
|
97
|
+
}
|
|
54
98
|
}
|
|
55
99
|
|
|
56
100
|
module.exports = BrunoResponse;
|
|
@@ -12,8 +12,6 @@ const { get } = require('lodash');
|
|
|
12
12
|
const Bru = require('../bru');
|
|
13
13
|
const BrunoRequest = require('../bruno-request');
|
|
14
14
|
const BrunoResponse = require('../bruno-response');
|
|
15
|
-
const Test = require('../test');
|
|
16
|
-
const TestResults = require('../test-results');
|
|
17
15
|
const { cleanJson } = require('../utils');
|
|
18
16
|
const { createBruTestResultMethods } = require('../utils/results');
|
|
19
17
|
|
|
@@ -65,6 +65,12 @@ const addBrunoResponseShimToContext = (vm, res) => {
|
|
|
65
65
|
vm.setProp(resFn, 'setBody', setBody);
|
|
66
66
|
setBody.dispose();
|
|
67
67
|
|
|
68
|
+
let getSize = vm.newFunction('getSize', function () {
|
|
69
|
+
return marshallToVm(res.getSize(), vm);
|
|
70
|
+
});
|
|
71
|
+
vm.setProp(resFn, 'getSize', getSize);
|
|
72
|
+
getSize.dispose();
|
|
73
|
+
|
|
68
74
|
vm.setProp(vm.global, 'res', resFn);
|
|
69
75
|
resFn.dispose();
|
|
70
76
|
};
|