@@ -251,8 +251,6 @@ describe('Multipart', () => {
251
251
it ( 'should parse multipart body' , async ( ) => {
252
252
const server = createServer ( async ( req : ReqWithBody , res ) => {
253
253
await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
254
-
255
- res . setHeader ( 'Content-Type' , 'multipart/form-data' )
256
254
res . end ( JSON . stringify ( req . body ) )
257
255
} )
258
256
@@ -297,8 +295,6 @@ describe('Multipart', () => {
297
295
const server = createServer ( async ( req : ReqWithBody , res ) => {
298
296
await multipart ( ) ( req , res , ( err ) => err && res . end ( err ) )
299
297
300
- res . setHeader ( 'Content-Type' , 'multipart/form-data; boundary=some-boundary' )
301
-
302
298
res . end ( JSON . stringify ( req . body ) )
303
299
} )
304
300
@@ -320,8 +316,6 @@ describe('Multipart', () => {
320
316
const server = createServer ( async ( req : ReqWithBody , res ) => {
321
317
await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
322
318
323
- res . setHeader ( 'Content-Type' , 'multipart/form-data; boundary=some-boundary' )
324
-
325
319
res . end ( JSON . stringify ( req . body ) )
326
320
} )
327
321
@@ -343,8 +337,6 @@ describe('Multipart', () => {
343
337
const server = createServer ( async ( req : ReqWithBody , res ) => {
344
338
await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
345
339
346
- res . setHeader ( 'Content-Type' , 'multipart/form-data; boundary=some-boundary' )
347
-
348
340
res . end ( 'GET is ignored' )
349
341
} )
350
342
@@ -364,8 +356,6 @@ describe('Multipart', () => {
364
356
const server = createServer ( async ( req : ReqWithBody < { file : [ File ] } > , res ) => {
365
357
await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
366
358
367
- res . setHeader ( 'Content-Type' , 'multipart/form-data' )
368
-
369
359
const formBuf = new Uint8Array ( await file . arrayBuffer ( ) )
370
360
const buf = new Uint8Array ( await req . body ! . file [ 0 ] . arrayBuffer ( ) )
371
361
@@ -395,8 +385,6 @@ describe('Multipart', () => {
395
385
const server = createServer ( async ( req : ReqWithBody < { file1 : [ File ] ; file2 : [ File ] } > , res ) => {
396
386
await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
397
387
398
- res . setHeader ( 'Content-Type' , 'multipart/form-data' )
399
-
400
388
const files = Object . values ( req . body ! )
401
389
402
390
for ( const file of files ) {
@@ -413,6 +401,30 @@ describe('Multipart', () => {
413
401
method : 'POST'
414
402
} ) . expect ( 200 )
415
403
} )
404
+ it ( 'should support binary files' , async ( ) => {
405
+ const fd = new FormData ( )
406
+ const file = new File ( [ new Uint8Array ( [ 1 , 2 , 3 ] ) ] , 'blob.bin' , { type : 'application/octet-stream' } )
407
+ fd . set ( 'file' , file )
408
+
409
+ const server = createServer ( async ( req : ReqWithBody < { file : [ File ] } > , res ) => {
410
+ await multipart ( ) ( req , res , ( err ) => err && console . log ( err ) )
411
+
412
+
413
+ const formBuf = new Uint8Array ( await file . arrayBuffer ( ) )
414
+ const buf = new Uint8Array ( await req . body ! . file [ 0 ] . arrayBuffer ( ) )
415
+
416
+ assert . equal ( Buffer . compare ( buf , formBuf ) , 0 )
417
+ assert . equal ( req . body ?. file [ 0 ] . type , 'application/octet-stream' )
418
+
419
+ res . end ( req . body ?. file [ 0 ] . name )
420
+ } )
421
+
422
+ await makeFetch ( server ) ( '/' , {
423
+ // probaly better to use form-data package
424
+ body : fd ,
425
+ method : 'POST'
426
+ } ) . expect ( 200 , 'blob.bin' )
427
+ } )
416
428
} )
417
429
418
430
describe ( 'Limits' , ( ) => {
0 commit comments