Skip to content

Commit 469f55a

Browse files
committed
fixup
1 parent 0db311b commit 469f55a

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/api/api-fetch/body.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const util = require('../../core/util')
44
const { finished } = require('stream')
55
const { ReadableStream, CountQueuingStrategy } = require('stream/web')
6-
const { AbortError, InvalidArgumentError } = require('../../core/errors')
6+
const { AbortError } = require('../../core/errors')
77

88
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
99
function extractBody (body) {
@@ -26,8 +26,13 @@ function extractBody (body) {
2626
} else if (
2727
body instanceof ArrayBuffer ||
2828
ArrayBuffer.isView(body) ||
29-
util.isBuffer(body)
29+
util.isBuffer(body) ||
30+
body instanceof DataView
3031
) {
32+
if (body instanceof DataView) {
33+
// TODO: Blob doesn't seem to work with DataView?
34+
body = body.buffer
35+
}
3136
return [{
3237
source: body
3338
}, null]

test/node-fetch/response.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ describe('Response', () => {
187187
})
188188
})
189189

190-
// it('should support DataView as body', () => {
191-
// const encoder = new TextEncoder()
192-
// const res = new Response(new DataView(encoder.encode('a=1').buffer))
193-
// return res.text().then(result => {
194-
// expect(result).to.equal('a=1')
195-
// })
196-
// })
190+
it('should support DataView as body', () => {
191+
const encoder = new TextEncoder()
192+
const res = new Response(new DataView(encoder.encode('a=1').buffer))
193+
return res.text().then(result => {
194+
expect(result).to.equal('a=1')
195+
})
196+
})
197197

198198
it('should default to null as body', () => {
199199
const res = new Response()

0 commit comments

Comments
 (0)