UNPKG

got

Version:

Human-friendly and powerful HTTP request library for Node.js

15 lines (14 loc) • 488 B
import is from '@sindresorhus/is'; import { stringToUint8Array } from 'uint8array-extras'; export default function getBodySize(body, headers) { if (headers && 'content-length' in headers && headers['content-length'] !== undefined) { return Number(headers['content-length']); } if (!body) { return 0; } if (is.string(body)) { return stringToUint8Array(body).byteLength; } return ArrayBuffer.isView(body) ? body.byteLength : undefined; }