()
| 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…