forked from idrinth-api-bench/issues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.ts
46 lines (42 loc) · 1.01 KB
/
result.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {
NeedleResponse,
} from 'needle';
import {
HashMap,
} from './hashmap.js';
const ToMicro = 1000000000;
export class Result {
public duration: number;
public response?: {
headers: HashMap;
cookies: HashMap;
body: string;
uri: string;
status: number;
};
// eslint-disable-next-line max-params
public constructor(
public id: string,
uri: string,
start: Array<number>,
end: Array<number>,
response: NeedleResponse,
public validators: Array<string>,
public maxDuration: number|undefined,
) {
this.duration = (end.shift() - start.shift()) * ToMicro;
this.duration += end.pop() - start.pop();
this.response = {
body: response.raw.toString(),
uri,
headers: {},
cookies: response.cookies || {},
status: response.statusCode,
};
for (const header in response.headers) {
if (typeof response.headers[header] === 'string') {
this.response.headers[header] = response.headers[header] as string;
}
}
}
}