From: Justin Wind Date: Sun, 23 Jul 2023 21:50:45 +0000 (-0700) Subject: remove deprecated ctx.rawBody usage X-Git-Tag: v2.0.0^2~7 X-Git-Url: http://git.squeep.com/?p=squeep-api-dingus;a=commitdiff_plain;h=552223cf6566d87e95a49175e80440fbe47a25b9 remove deprecated ctx.rawBody usage --- 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); });