File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33const util = require ( '../../core/util' )
44const { finished } = require ( 'stream' )
55const { 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
99function 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 ]
Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments