* Parse rawBody as contentType into ctx.parsedBody.
* @param {string} contentType
* @param {object} ctx
- * @param {string|buffer}
+ * @param {string|buffer} rawBody
*/
parseBody(contentType, ctx, rawBody) {
const _scope = _fileScope('parseBody');
- if (!rawBody) {
- // 1.2.4 and earlier expected rawBody on context
- rawBody = ctx.rawBody;
- }
-
switch (contentType) {
case Enum.ContentType.ApplicationForm:
ctx.parsedBody = this.querystring.parse(rawBody);
});
it('parses json', function () {
const src = { foo: 'bar' };
- ctx.rawBody = JSON.stringify(src);
- dingus.parseBody(Enum.ContentType.ApplicationJson, ctx);
+ const rawBody = JSON.stringify(src);
+ dingus.parseBody(Enum.ContentType.ApplicationJson, ctx, rawBody);
assert.deepStrictEqual(ctx.parsedBody, src);
});
it('handles unparsable json', function () {
- ctx.rawBody = 'not json';
+ const rawBody = 'not json';
try {
- dingus.parseBody(Enum.ContentType.ApplicationJson, ctx);
+ dingus.parseBody(Enum.ContentType.ApplicationJson, ctx, rawBody);
assert.fail(noExpectedException);
} catch (e) {
assert.strictEqual(e.statusCode, 400);
const expected = Object.assign(Object.create(null), {
foo: 'bar',
});
- ctx.rawBody = 'foo=bar';
- dingus.parseBody('application/x-www-form-urlencoded', ctx);
+ const rawBody = 'foo=bar';
+ dingus.parseBody('application/x-www-form-urlencoded', ctx, rawBody);
assert.deepStrictEqual(ctx.parsedBody, expected);
});