Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 5, 2021
1 parent 0db311b commit 469f55a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions lib/api/api-fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions test/node-fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 469f55a

Please sign in to comment.