bodyparser icon indicating copy to clipboard operation
bodyparser copied to clipboard

can not parse no content-type body

Open iyaozhen opened this issue 5 years ago • 3 comments

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 😭

iyaozhen avatar Apr 20 '20 04:04 iyaozhen

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.

dead-horse avatar Apr 20 '20 05:04 dead-horse

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

iyaozhen avatar Jul 02 '20 05:07 iyaozhen

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

3imed-jaberi avatar Mar 31 '23 16:03 3imed-jaberi

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!

3imed-jaberi avatar Apr 07 '24 04:04 3imed-jaberi