MCPcopy Create free account
hub / github.com/expressjs/body-parser / contentstream

Function contentstream

lib/read.js:151–188  ·  view source on GitHub ↗

* Get the content stream of the request. * * @param {object} req * @param {function} debug * @param {boolean} [inflate=true] * @return {object} * @api private

(req, debug, inflate)

Source from the content-addressed store, hash-verified

149 */
150
151function contentstream (req, debug, inflate) {
152 var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
153 var length = req.headers['content-length']
154 var stream
155
156 debug('content-encoding "%s"', encoding)
157
158 if (inflate === false && encoding !== 'identity') {
159 throw createError(415, 'content encoding unsupported', {
160 encoding: encoding,
161 type: 'encoding.unsupported'
162 })
163 }
164
165 switch (encoding) {
166 case 'deflate':
167 stream = zlib.createInflate()
168 debug('inflate body')
169 req.pipe(stream)
170 break
171 case 'gzip':
172 stream = zlib.createGunzip()
173 debug('gunzip body')
174 req.pipe(stream)
175 break
176 case 'identity':
177 stream = req
178 stream.length = length
179 break
180 default:
181 throw createError(415, 'unsupported content encoding "' + encoding + '"', {
182 encoding: encoding,
183 type: 'encoding.unsupported'
184 })
185 }
186
187 return stream
188}
189
190/**
191 * Dump the contents of a request.

Callers 1

readFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected