loadtest 8.0.7 → 8.0.9
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/.loadtestrc +2 -0
- package/doc/api.md +2 -1
- package/lib/headers.js +12 -7
- package/lib/options.js +1 -1
- package/package.json +1 -1
- package/test/headers.js +5 -3
package/.loadtestrc
ADDED
package/doc/api.md
CHANGED
|
@@ -109,7 +109,8 @@ An array of cookies to send. Each cookie should be a string of the form `name=va
|
|
|
109
109
|
|
|
110
110
|
#### `headers`
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
An object containing headers of the form `key: 'value'}.
|
|
113
|
+
Each attribute of the object should be a header with the value given as a string.
|
|
113
114
|
If you want to have several values for a header, write a single value separated by semicolons,
|
|
114
115
|
like this:
|
|
115
116
|
|
package/lib/headers.js
CHANGED
|
@@ -6,25 +6,30 @@
|
|
|
6
6
|
export function addHeaders(rawHeaders, headers) {
|
|
7
7
|
if (Array.isArray(rawHeaders)) {
|
|
8
8
|
rawHeaders.forEach(function(header) {
|
|
9
|
-
|
|
9
|
+
addTextHeader(header, headers);
|
|
10
10
|
});
|
|
11
11
|
} else if (typeof rawHeaders == 'string') {
|
|
12
|
-
|
|
12
|
+
addTextHeader(rawHeaders, headers);
|
|
13
|
+
} else if (typeof rawHeaders == 'object') {
|
|
14
|
+
for (const key of Object.keys(rawHeaders)) {
|
|
15
|
+
addHeader(key, rawHeaders[key], headers)
|
|
16
|
+
}
|
|
13
17
|
} else {
|
|
14
18
|
console.error('Invalid header structure %j, it should be an array', rawHeaders);
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
* Add a single header to an array.
|
|
20
|
-
*/
|
|
21
|
-
function addHeader(rawHeader, headers) {
|
|
22
|
+
function addTextHeader(rawHeader, headers) {
|
|
22
23
|
if (!rawHeader.includes(':')) {
|
|
23
24
|
return console.error('Invalid header %s, it should be in the form -H key:value', rawHeader);
|
|
24
25
|
}
|
|
25
26
|
const index = rawHeader.indexOf(':');
|
|
26
27
|
const key = rawHeader.substr(0, index);
|
|
27
28
|
const value = rawHeader.substr(index + 1);
|
|
29
|
+
addHeader(key, value, headers)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function addHeader(key, value, headers) {
|
|
28
33
|
headers[key.toLowerCase()] = value;
|
|
29
34
|
}
|
|
30
35
|
|
|
@@ -33,7 +38,7 @@ function addHeader(rawHeader, headers) {
|
|
|
33
38
|
*/
|
|
34
39
|
export function addUserAgent(headers) {
|
|
35
40
|
if(!headers['user-agent']) {
|
|
36
|
-
|
|
41
|
+
addHeader('user-agent', 'node.js loadtest bot', headers)
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
package/lib/options.js
CHANGED
|
@@ -118,7 +118,7 @@ class Options {
|
|
|
118
118
|
if (this.certFile) {
|
|
119
119
|
this.cert = await readFile(this.certFile);
|
|
120
120
|
}
|
|
121
|
-
if (typeof this.requestGenerator == 'string') {
|
|
121
|
+
if (this.requestGenerator && typeof this.requestGenerator == 'string') {
|
|
122
122
|
this.requestGenerator = await import(this.requestGenerator)
|
|
123
123
|
}
|
|
124
124
|
if (this.bodyFile) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadtest",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Run load tests for your web application. Mostly ab-compatible interface, with an option to force requests per second. Includes an API for automated load testing.",
|
|
6
6
|
"homepage": "https://github.com/alexfernandez/loadtest",
|
package/test/headers.js
CHANGED
|
@@ -3,7 +3,7 @@ import {addHeaders, addUserAgent} from '../lib/headers.js'
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function testAddHeaders(callback) {
|
|
6
|
-
const tests = [
|
|
6
|
+
const tests = [{
|
|
7
7
|
raw: 'k:v',
|
|
8
8
|
headers: { 'k': 'v' }
|
|
9
9
|
}, {
|
|
@@ -18,8 +18,10 @@ function testAddHeaders(callback) {
|
|
|
18
18
|
}, {
|
|
19
19
|
raw: 'k:v:w',
|
|
20
20
|
headers: { 'k': 'v:w' }
|
|
21
|
-
}
|
|
22
|
-
|
|
21
|
+
}, {
|
|
22
|
+
raw: {accept: 'text/plain;text/html'},
|
|
23
|
+
headers: {accept: 'text/plain;text/html'},
|
|
24
|
+
}];
|
|
23
25
|
tests.forEach(function(test) {
|
|
24
26
|
const headers = {};
|
|
25
27
|
addHeaders(test.raw, headers);
|