Files
Ivan Montiel 10558c8283 Stop stripping newlines and tabs from body
This change introduces request.rawPayload to the Hapi request
and uses that if request.payload is not a string.

Before, JSON.stringify(JSON.parse(request.payload)) was being
used, which is not the same as the rawPayload that should be
passed along.
2017-12-16 17:21:00 -07:00

42 lines
801 B
JavaScript

'use strict';
module.exports = class RequestBuilder {
constructor(method, path) {
this.request = {
method: method.toUpperCase(),
headers: {},
unprocessedHeaders: {},
params: {},
route: {
path,
},
query: {},
payload: null,
rawPayload: null,
info: {
remoteAddress: '127.0.0.1',
},
};
}
addHeader(key, value) {
this.request.headers[key] = value;
this.request.unprocessedHeaders[key] = 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;
}
toObject() {
return this.request;
}
};