MCPcopy
hub / github.com/expressjs/body-parser / read

Function read

lib/read.js:39–173  ·  view source on GitHub ↗

* Read a request into a buffer and parse. * * @param {Object} req * @param {Object} res * @param {Function} next * @param {Function} parse * @param {Function} debug * @param {Object} options * @private

(req, res, next, parse, debug, options)

Source from the content-addressed store, hash-verified

37 * @private
38 */
39function read (req, res, next, parse, debug, options) {
40 if (onFinished.isFinished(req)) {
41 debug('body already parsed')
42 next()
43 return
44 }
45
46 if (!('body' in req)) {
47 req.body = undefined
48 }
49
50 // skip requests without bodies
51 if (!hasBody(req)) {
52 debug('skip empty body')
53 next()
54 return
55 }
56
57 debug('content-type %j', req.headers['content-type'])
58
59 // determine if request should be parsed
60 if (!options.shouldParse(req)) {
61 debug('skip parsing')
62 next()
63 return
64 }
65
66 let encoding = null
67 if (options?.skipCharset !== true) {
68 encoding = getCharset(req) || options.defaultCharset
69
70 // validate charset
71 if (!!options?.isValidCharset && !options.isValidCharset(encoding)) {
72 debug('invalid charset')
73 next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
74 charset: encoding,
75 type: 'charset.unsupported'
76 }))
77 return
78 }
79 }
80
81 let length
82 const opts = options
83 let stream
84
85 // read options
86 const verify = opts.verify
87
88 try {
89 // get the content stream
90 stream = contentstream(req, debug, opts.inflate)
91 length = stream.length
92 stream.length = undefined
93 } catch (err) {
94 return next(err)
95 }
96

Callers 4

jsonFunction · 0.85
textFunction · 0.85
rawFunction · 0.85
urlencodedFunction · 0.85

Calls 4

getCharsetFunction · 0.85
contentstreamFunction · 0.85
dumpFunction · 0.85
verifyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…