From 1536e41d93b114a114e099dc8eb8434ced75602b Mon Sep 17 00:00:00 2001 From: WolfieLeader Date: Thu, 13 Aug 2026 17:30:02 +0300 Subject: [PATCH 1/4] feat: parse bodies for the HTTP QUERY method --- README.md | 2 +- src/body-parser.ts | 2 +- src/body-parser.types.ts | 2 +- test/middleware.test.ts | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7dc4781..b6525d4 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ app.use((ctx) => { - **enableRawChecking**: support the already parsed body on the raw request by override and prioritize the parsed value over the sended payload. (default is `false`) -- **parsedMethods**: declares the HTTP methods where bodies will be parsed, default `['POST', 'PUT', 'PATCH']`. +- **parsedMethods**: declares the HTTP methods where bodies will be parsed, default `['POST', 'PUT', 'PATCH', 'QUERY']`. - **disableBodyParser**: you can dynamic disable body parser by set `ctx.disableBodyParser = true`. diff --git a/src/body-parser.ts b/src/body-parser.ts index cf061be..4fdc075 100644 --- a/src/body-parser.ts +++ b/src/body-parser.ts @@ -27,7 +27,7 @@ declare module 'http' { export function bodyParserWrapper(opts: BodyParserOptions = {}) { const { patchNode = false, - parsedMethods = ['POST', 'PUT', 'PATCH'], + parsedMethods = ['POST', 'PUT', 'PATCH', 'QUERY'], detectJSON, onError, enableTypes = ['json', 'form'], diff --git a/src/body-parser.types.ts b/src/body-parser.types.ts index 5d3226b..85bd9c8 100644 --- a/src/body-parser.types.ts +++ b/src/body-parser.types.ts @@ -13,7 +13,7 @@ export type BodyType = (typeof supportedBodyTypes)[number]; export type BodyParserOptions = { /** * declares the HTTP methods where bodies will be parsed. - * @default ['POST', 'PUT', 'PATCH'] + * @default ['POST', 'PUT', 'PATCH', 'QUERY'] */ parsedMethods?: string[]; /** diff --git a/test/middleware.test.ts b/test/middleware.test.ts index e6babe2..9bda440 100644 --- a/test/middleware.test.ts +++ b/test/middleware.test.ts @@ -483,6 +483,22 @@ describe('test/body-parser.test.ts', () => { }); }); + describe('parsedMethods', () => { + it('should parse json body on QUERY request', async () => { + const app = createApp(); + + app.use(async (ctx) => { + expect(ctx.request.body).toEqual({ foo: 'bar' }); + expect(ctx.request.rawBody).toEqual('{"foo":"bar"}'); + ctx.body = ctx.request.body; + }); + + await new request.Test(app.callback(), 'QUERY', '/') + .send({ foo: 'bar' }) + .expect({ foo: 'bar' }); + }); + }); + describe('onError', () => { const app = createApp({ onError({}, ctx) { From b7beaf691069fdd56dd3e3d37e5c28525994eace Mon Sep 17 00:00:00 2001 From: WolfieLeader Date: Thu, 13 Aug 2026 17:58:21 +0300 Subject: [PATCH 2/4] test: cover parsedMethods opt-out for QUERY --- test/middleware.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/middleware.test.ts b/test/middleware.test.ts index 9bda440..33eef04 100644 --- a/test/middleware.test.ts +++ b/test/middleware.test.ts @@ -497,6 +497,19 @@ describe('test/body-parser.test.ts', () => { .send({ foo: 'bar' }) .expect({ foo: 'bar' }); }); + + it('should not parse body on QUERY request when parsedMethods omits it', async () => { + const app = createApp({ parsedMethods: ['POST', 'PUT', 'PATCH'] }); + + app.use(async (ctx) => { + expect(ctx.request.body).toBeUndefined(); + ctx.body = ctx.request.body; + }); + + await new request.Test(app.callback(), 'QUERY', '/') + .send({ foo: 'bar' }) + .expect({}); + }); }); describe('onError', () => { From 4d391a396381ad964ce6d606b86a61b93db130c1 Mon Sep 17 00:00:00 2001 From: WolfieLeader Date: Thu, 13 Aug 2026 18:02:00 +0300 Subject: [PATCH 3/4] docs: fix typo in enableRawChecking description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6525d4..3b09e35 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ app.use((ctx) => { ); ``` -- **enableRawChecking**: support the already parsed body on the raw request by override and prioritize the parsed value over the sended payload. (default is `false`) +- **enableRawChecking**: support the already parsed body on the raw request by override and prioritize the parsed value over the sent payload. (default is `false`) - **parsedMethods**: declares the HTTP methods where bodies will be parsed, default `['POST', 'PUT', 'PATCH', 'QUERY']`. From 8d5cac8aeeb336190f1830d9808e390c81d15f6c Mon Sep 17 00:00:00 2001 From: WolfieLeader Date: Thu, 13 Aug 2026 19:16:47 +0300 Subject: [PATCH 4/4] docs: fix grammar in disableBodyParser description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b09e35..348a56a 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ app.use((ctx) => { - **parsedMethods**: declares the HTTP methods where bodies will be parsed, default `['POST', 'PUT', 'PATCH', 'QUERY']`. -- **disableBodyParser**: you can dynamic disable body parser by set `ctx.disableBodyParser = true`. +- **disableBodyParser**: you can dynamically disable the body parser by setting `ctx.disableBodyParser = true`. ```js app.use((ctx, next) => {