@@ -40,6 +40,8 @@ export default function Body(body, {
40
40
// body is blob
41
41
} else if ( Buffer . isBuffer ( body ) ) {
42
42
// body is buffer
43
+ } else if ( Object . prototype . toString . call ( body ) === '[object ArrayBuffer]' ) {
44
+ // body is array buffer
43
45
} else if ( body instanceof Stream ) {
44
46
// body is stream
45
47
} else {
@@ -202,6 +204,11 @@ function consumeBody() {
202
204
return Body . Promise . resolve ( this . body ) ;
203
205
}
204
206
207
+ // body is buffer
208
+ if ( Object . prototype . toString . call ( this . body ) === '[object ArrayBuffer]' ) {
209
+ return Body . Promise . resolve ( this . body ) ;
210
+ }
211
+
205
212
// istanbul ignore if: should never happen
206
213
if ( ! ( this . body instanceof Stream ) ) {
207
214
return Body . Promise . resolve ( Buffer . alloc ( 0 ) ) ;
@@ -403,6 +410,9 @@ export function extractContentType(instance) {
403
410
} else if ( Buffer . isBuffer ( body ) ) {
404
411
// body is buffer
405
412
return null ;
413
+ } else if ( Object . prototype . toString . call ( body ) === '[object ArrayBuffer]' ) {
414
+ // body is array buffer
415
+ return null ;
406
416
} else if ( typeof body . getBoundary === 'function' ) {
407
417
// detect form data input from form-data module
408
418
return `multipart/form-data;boundary=${ body . getBoundary ( ) } ` ;
@@ -441,6 +451,9 @@ export function getTotalBytes(instance) {
441
451
} else if ( Buffer . isBuffer ( body ) ) {
442
452
// body is buffer
443
453
return body . length ;
454
+ } else if ( Object . prototype . toString . call ( body ) === '[object ArrayBuffer]' ) {
455
+ // body is array buffer
456
+ return body . byteLength ;
444
457
} else if ( body && typeof body . getLengthSync === 'function' ) {
445
458
// detect form data input from form-data module
446
459
if ( body . _lengthRetrievers && body . _lengthRetrievers . length == 0 || // 1.x
@@ -483,6 +496,10 @@ export function writeToStream(dest, instance) {
483
496
// body is buffer
484
497
dest . write ( body ) ;
485
498
dest . end ( )
499
+ } else if ( Object . prototype . toString . call ( body ) === '[object ArrayBuffer]' ) {
500
+ // body is array buffer
501
+ dest . write ( Buffer . from ( body ) ) ;
502
+ dest . end ( )
486
503
} else {
487
504
// body is stream
488
505
body . pipe ( dest ) ;
0 commit comments