koajs / bodyparser

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

request body is an empty object for GET requests #109

Closed piotr-s-brainhub closed 5 years ago

piotr-s-brainhub commented 5 years ago

Request body is an empty object for GET requests but IMO it should be undefined.

piotr-s-brainhub commented 5 years ago

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

dead-horse commented 5 years ago

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).