Skip to content

Commit

Permalink
Use on-finished to determine when body read
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Dec 16, 2021
1 parent 9eb206b commit 08d95a4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
===

* `urlencoded` parser now defaults `extended` to `false`
* Use `on-finished` to determine when body read

1.19.1 / 2021-12-10
===================
Expand Down
3 changes: 0 additions & 3 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ function read (req, res, next, parse, debug, options) {
var opts = options
var stream

// flag as parsed
req._body = true

// read options
var encoding = opts.encoding !== null
? opts.encoding
Expand Down
3 changes: 2 additions & 1 deletion lib/types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var bytes = require('bytes')
var contentType = require('content-type')
var createError = require('http-errors')
var debug = require('debug')('body-parser:json')
var isFinished = require('on-finished').isFinished
var read = require('../read')
var typeis = require('type-is')

Expand Down Expand Up @@ -96,7 +97,7 @@ function json (options) {
}

return function jsonParser (req, res, next) {
if (req._body) {
if (isFinished(req)) {
debug('body already parsed')
next()
return
Expand Down
3 changes: 2 additions & 1 deletion lib/types/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

var bytes = require('bytes')
var debug = require('debug')('body-parser:raw')
var isFinished = require('on-finished').isFinished
var read = require('../read')
var typeis = require('type-is')

Expand Down Expand Up @@ -53,7 +54,7 @@ function raw (options) {
}

return function rawParser (req, res, next) {
if (req._body) {
if (isFinished(req)) {
debug('body already parsed')
next()
return
Expand Down
3 changes: 2 additions & 1 deletion lib/types/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
var bytes = require('bytes')
var contentType = require('content-type')
var debug = require('debug')('body-parser:text')
var isFinished = require('on-finished').isFinished
var read = require('../read')
var typeis = require('type-is')

Expand Down Expand Up @@ -55,7 +56,7 @@ function text (options) {
}

return function textParser (req, res, next) {
if (req._body) {
if (isFinished(req)) {
debug('body already parsed')
next()
return
Expand Down
3 changes: 2 additions & 1 deletion lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var bytes = require('bytes')
var contentType = require('content-type')
var createError = require('http-errors')
var debug = require('debug')('body-parser:urlencoded')
var isFinished = require('on-finished').isFinished
var read = require('../read')
var typeis = require('type-is')

Expand Down Expand Up @@ -71,7 +72,7 @@ function urlencoded (options) {
}

return function urlencodedParser (req, res, next) {
if (req._body) {
if (isFinished(req)) {
debug('body already parsed')
next()
return
Expand Down

0 comments on commit 08d95a4

Please sign in to comment.