koajs / bodyparser

Koa body parsing middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

request body is an empty object for GET requests

piotr-s-brainhub opened this issue · comments

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

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

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