koajs / bodyparser

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

can not parse no content-type body #136

Closed iyaozhen closed 7 months ago

iyaozhen commented 4 years ago

demo code

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');

const app = new Koa();
app.use(bodyParser({enableTypes: ['form', 'text'], extendTypes: {text: ['', undefined]}}));

app.use(async function() {
  // the parsed body will store in this.request.body
  this.body = this.request.body;
});

const PORT = process.env.PORT || 3000;

app.listen(PORT, () =>
  console.log(`Server ready at http://localhost:${PORT} 🚀 ..`)
);

test request

curl --location --request POST 'http://127.0.0.1:3000' \
--header 'Content-Type: ' \
--data-raw 'text'

debug parseBody first judge content type then parse it, but content type is undefined. And I try extendTypes, but build-in typeis try fase when it is undefined image

In some times, client request not standard, but as a server we will compatible it. sad 😭

dead-horse commented 4 years ago

why can you set a meaningful content-type header? or you can just use https://github.com/stream-utils/raw-body#simple-koa-example directly.

iyaozhen commented 4 years ago

Because client request is another user, I cant not control It,But as a server we will compatible it.

3imed-jaberi commented 1 year ago

I'm not sure, but we can add an option to enable support for the unknown request type as text. @dead-horse ?!

3imed-jaberi commented 7 months ago

This issue opened for a long time and I think @iyaozhen followed at the end what @dead-horse mentioned, therefore I am closing this issue, and please feel free to re-open at anytime if you feel like you realy need this feature today!