cojs / co-body

Parse request bodies with co
MIT License
325 stars 42 forks source link

fixes a bug that carries the content length from previous requests #48

Closed dgaya closed 7 years ago

dgaya commented 8 years ago

Related to #44 .

Bug description

When mixed compressed and uncompressed requests happen and the caller is using a shared options object (like koa-bodyparser does), then the length of the previous request is carried to the next request giving the following error:

Error: request size did not match content length
      at Unzip.onEnd (./koa-bodyparser/node_modules/co-body/node_modules/raw-body/index.js:298:12)
      at emitNone (events.js:72:20)
      at Unzip.emit (events.js:166:7)
      at endReadableNT (_stream_readable.js:905:12)
      at nextTickCallbackWith2Args (node.js:437:9)
      at process._tickCallback (node.js:351:17)

See the test added to reproduce it.

Fix

{
    encoding: opts.encoding,
    limit: opts.limit,
    length: opts.length
}
luin commented 7 years ago

Where are we on this pull request?

It seems to be a pretty serious bug especially after this pull request (https://github.com/cojs/co-body/pull/54/files) being merged since the shared options keep existing across different event loops. The error request size did not match content length happens frequently under high concurrency.

dead-horse commented 7 years ago

@luin sorry, I'll take a look at this