diff --git a/lib/xmlhttprequest.js b/lib/xmlhttprequest.js index ba631bb..adfe94d 100644 --- a/lib/xmlhttprequest.js +++ b/lib/xmlhttprequest.js @@ -339,7 +339,11 @@ class XMLHttpRequest extends XMLHttpRequestEventTarget { client.setHeader(key, value); }); _readyStateChange.call(this, XMLHttpRequest.HEADERS_RECEIVED); - if (typeof body === 'string' || body instanceof FormData) { + if (body instanceof Uint8Array || body instanceof ArrayBuffer) { + body = Buffer.from(body); + } + if (typeof body === 'string' || body instanceof Buffer || body instanceof FormData) { + client.setHeader('Content-Length', Buffer.isBuffer(body) ? body.length : Buffer.byteLength(body)); client.on('socket', _setDispatchProgressEvents.bind(this.upload)); client.write(body); }