From 5f18a2f2949657e77c73cbeabd09cdecf6c795c3 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Wed, 1 Jun 2022 01:08:09 +0800 Subject: [PATCH] fix: support `TypedArray` and `DataView` as Request body --- lib/core/request.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/core/request.js b/lib/core/request.js index 2a13b0549a8..bbbac106833 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -80,13 +80,12 @@ class Request { this.body = null } else if (util.isStream(body)) { this.body = body - } else if (body instanceof DataView) { - // TODO: Why is DataView special? - this.body = body.buffer.byteLength ? Buffer.from(body.buffer) : null - } else if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) { - this.body = body.byteLength ? Buffer.from(body) : null } else if (util.isBuffer(body)) { this.body = body.byteLength ? body : null + } else if (ArrayBuffer.isView(body)) { + this.body = body.buffer.byteLength ? Buffer.from(body.buffer, body.byteOffset, body.byteLength) : null + } else if (body instanceof ArrayBuffer) { + this.body = body.byteLength ? Buffer.from(body) : null } else if (typeof body === 'string') { this.body = body.length ? Buffer.from(body) : null } else if (util.isFormDataLike(body) || util.isIterable(body) || util.isBlobLike(body)) {