request body is an empty object for GET requests
piotr-s-brainhub opened this issue · comments
piotr-s-brainhub commented
Request body is an empty object for GET requests but IMO it should be undefined
.
piotr-s-brainhub commented
I did a workaround with:
if (!['post', 'put', 'patch'].includes(ctx.method.toLowerCase())) {
ctx.disableBodyParser = true;
}
await next();
});
however IMO this should be the default behavior - in order to avoid breaking backwards compatibility, you could update the default behavior in the next major release
Yiyu He commented
ctx.request.body
is always return an object to simplify application's code(no need to detect if ctx.request.body
's type), this is by design. Actually you don't even touch ctx.request.body
when you don't expect the request will have body( etc. when request is GET, HEAD).