MCPcopy
hub / github.com/request/request / setContentLength

Function setContentLength

request.js:419–440  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

417 }
418
419 function setContentLength () {
420 if (isTypedArray(self.body)) {
421 self.body = Buffer.from(self.body)
422 }
423
424 if (!self.hasHeader('content-length')) {
425 var length
426 if (typeof self.body === 'string') {
427 length = Buffer.byteLength(self.body)
428 } else if (Array.isArray(self.body)) {
429 length = self.body.reduce(function (a, b) { return a + b.length }, 0)
430 } else {
431 length = self.body.length
432 }
433
434 if (length) {
435 self.setHeader('content-length', length)
436 } else {
437 self.emit('error', new Error('Argument error, options.body.'))
438 }
439 }
440 }
441 if (self.body && !isstream(self.body)) {
442 setContentLength()
443 }

Callers 2

request.jsFile · 0.85
endFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…