From 469f55a9eb3a101713f748967901289efafabf73 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Thu, 5 Aug 2021 10:38:32 +0200 Subject: [PATCH] fixup --- lib/api/api-fetch/body.js | 9 +++++++-- test/node-fetch/response.js | 14 +++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/api/api-fetch/body.js b/lib/api/api-fetch/body.js index 1991f596c42..e5866a6fdd1 100644 --- a/lib/api/api-fetch/body.js +++ b/lib/api/api-fetch/body.js @@ -3,7 +3,7 @@ const util = require('../../core/util') const { finished } = require('stream') const { ReadableStream, CountQueuingStrategy } = require('stream/web') -const { AbortError, InvalidArgumentError } = require('../../core/errors') +const { AbortError } = require('../../core/errors') // https://fetch.spec.whatwg.org/#concept-bodyinit-extract function extractBody (body) { @@ -26,8 +26,13 @@ function extractBody (body) { } else if ( body instanceof ArrayBuffer || ArrayBuffer.isView(body) || - util.isBuffer(body) + util.isBuffer(body) || + body instanceof DataView ) { + if (body instanceof DataView) { + // TODO: Blob doesn't seem to work with DataView? + body = body.buffer + } return [{ source: body }, null] diff --git a/test/node-fetch/response.js b/test/node-fetch/response.js index 5d14acf376b..332f323110c 100644 --- a/test/node-fetch/response.js +++ b/test/node-fetch/response.js @@ -187,13 +187,13 @@ describe('Response', () => { }) }) - // it('should support DataView as body', () => { - // const encoder = new TextEncoder() - // const res = new Response(new DataView(encoder.encode('a=1').buffer)) - // return res.text().then(result => { - // expect(result).to.equal('a=1') - // }) - // }) + it('should support DataView as body', () => { + const encoder = new TextEncoder() + const res = new Response(new DataView(encoder.encode('a=1').buffer)) + return res.text().then(result => { + expect(result).to.equal('a=1') + }) + }) it('should default to null as body', () => { const res = new Response()