1
0
Fork 0

Add req.json

This commit is contained in:
Alan Plum 2016-04-20 17:18:43 +02:00
parent 7065d29975
commit 96aa1d9129
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
1 changed files with 8 additions and 0 deletions

View File

@ -44,6 +44,7 @@ module.exports = class SyntheticRequest {
this.pathParams = {};
this.queryParams = querystring.decode(this._url.query);
this.body = getRawBodyBuffer(req);
this.rawBody = this.body;
const server = extractServer(req, context.trustProxy);
this.protocol = server.protocol;
@ -145,6 +146,13 @@ module.exports = class SyntheticRequest {
return this._raw.database;
}
json() {
if (!this.rawBody) {
return undefined;
}
return JSON.parse(this.rawBody.toString('utf-8'));
}
params(name) {
if (hasOwnProperty.call(this.pathParams, name)) {
return this.pathParams[name];