koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 116 forks source link

if nothing was parsed why does ctx.request.body have a value? #80

Closed 75lb closed 7 years ago

75lb commented 7 years ago

If nothing was parsed why does ctx.request.body have a value (empty object)?

In both these cases ctx.request.body equals {}: a) The request body was empty b) The request body was '{}'

How do I distinguish whether the request body was empty or '{}'? What's the recommended method to test whether the request body is empty?

dead-horse commented 7 years ago

this is by design, so you don't need to check body exists every time.

you can use ctx.request.rawBody to get the original request body string. https://github.com/koajs/bodyparser#raw-body