Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: koa-body Sets ctx.request.body to {} by Default, Preventing Proper Parsing #238

Open
arjungowda-zs opened this issue Feb 27, 2025 · 0 comments · May be fixed by #239
Open

Bug: koa-body Sets ctx.request.body to {} by Default, Preventing Proper Parsing #238

arjungowda-zs opened this issue Feb 27, 2025 · 0 comments · May be fixed by #239
Assignees

Comments

@arjungowda-zs
Copy link

{},

Description

koa-body sets ctx.request.body = {} even when no body is parsed (index.ts#L109). This prevents other middleware from correctly determining whether a request body exists.

For example, koa-bodyparser (index.js#L64) only parses the request if ctx.request.body is undefined. Since koa-body sets it to {}, koa-bodyparser skips parsing, causing unexpected behavior.

Expected Behavior

If no body is parsed, ctx.request.body should remain undefined so that downstream middleware (including koa-bodyparser) can handle it appropriately.

Steps to Reproduce

Use koa-body in a Koa app.
Send a request without a body (e.g., a GET request or an empty POST request).
Observe that ctx.request.body is {} instead of undefined, which may prevent other middleware from handling the request properly.

Possible Fix

Avoid setting "{}" when the request body is not parsed.

@TheDadi TheDadi linked a pull request Mar 14, 2025 that will close this issue
6 tasks
@TheDadi TheDadi self-assigned this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants