-
-
Notifications
You must be signed in to change notification settings - Fork 793
/
RequestBuilder.js
47 lines (41 loc) · 1012 Bytes
/
RequestBuilder.js
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
47
module.exports = class RequestBuilder {
constructor(method, path) {
this.request = {
method: method.toUpperCase(),
headers: {},
multiValueHeaders: {},
unprocessedHeaders: {},
params: {},
route: {
path,
},
query: {},
payload: null,
rawPayload: null,
info: {
remoteAddress: '127.0.0.1',
received: 1,
},
};
}
addHeader(key, value) {
this.request.headers[key] = value;
this.request.unprocessedHeaders[key] = value;
this.request.multiValueHeaders[key] =
(this.request.multiValueHeaders[key] || []).concat(value);
}
addBody(body) {
this.request.payload = body;
// The rawPayload would normally be the string version of the given body
this.request.rawPayload = JSON.stringify(body);
}
addParam(key, value) {
this.request.params[key] = value;
}
addQuery(key, value) {
this.request.query[key] = value;
}
toObject() {
return this.request;
}
};