From 552223cf6566d87e95a49175e80440fbe47a25b9 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Sun, 23 Jul 2023 14:50:45 -0700 Subject: [PATCH] remove deprecated ctx.rawBody usage --- lib/dingus.js | 7 +------ test/lib/dingus.js | 12 ++++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/dingus.js b/lib/dingus.js index 0057685..5b4643c 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -313,16 +313,11 @@ class Dingus { * 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); diff --git a/test/lib/dingus.js b/test/lib/dingus.js index b60caca..f374ba7 100644 --- a/test/lib/dingus.js +++ b/test/lib/dingus.js @@ -477,14 +477,14 @@ describe('Dingus', function () { }); 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); @@ -494,8 +494,8 @@ describe('Dingus', function () { 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); }); -- 2.43.2