stream-utils / raw-body

Get and validate the raw body of a readable stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Content-Type: text/xml Can not parse

woodenfish opened this issue · comments

demo code like this:

app.use(function* (next) {
  var string = yield getRawBody(this.req, {
    length: this.length,
    limit: '1mb',
    encoding: this.charset
  })
  this.body = string;
});

when I request using curl

curl -d 'xxxxxxxxxxxxxxx' 'http://localhost:80/' -H 'Content-Type: application/xml'

It's ok. But when I change the Content-Type to text/xml. It can not be parsed.

curl -d 'xxxxxxxxxxxxxxx' 'http://localhost:80/' -H 'Content-Type: text/xml'

Hi @woodenfish, I'm sorry to say, but I think you may have tracked the bug you are encountering to the wrong module. For example, this module never even looks at the Content-Type header (or any header, for that matter; we only take a stream as the first argument and the options you provide; this module is a general stream utility, and though commonly used to read the req stream, has no knowledge of HTTP semantics).

I really don't know much about Koa, but from looking at the documentation, it does not look like you are not even using it correctly, as this.length and this.charset actually corresponds to the response on the context, and not on the request. I also see this is the example in the README, so looks like I just need to fix the README.