koajs / koa-body

koa body parser middleware
MIT License
950 stars 130 forks source link

Please check if body has already been bound to ctx.request before parsing the raw body. #115

Open LvChengbin opened 6 years ago

LvChengbin commented 6 years ago

Just like the code in koa-bodyparser https://github.com/koajs/bodyparser/blob/master/index.js#L72

 return async function bodyParser(ctx, next) {
    if (ctx.request.body !== undefined) return await next();
    if (ctx.disableBodyParser) return await next();
}

Without checking it, koa-body will make requests be pending there if the raw body has already been parsed by other middleware because the Promise cannot be resolved in https://github.com/dlau/koa-body/blob/master/index.js#L84

MarkHerhold commented 5 years ago

This could be potentially breaking behavior but I'd accept a PR adding this for the next major version.