@@ -10,7 +10,7 @@ const { Writable, pipeline, PassThrough, Readable } = require('node:stream')
10
10
11
11
const pem = require ( 'https-pem' )
12
12
13
- const { Client, Agent } = require ( '..' )
13
+ const { Client, Agent, FormData } = require ( '..' )
14
14
15
15
const isGreaterThanv20 = process . versions . node . split ( '.' ) . map ( Number ) [ 0 ] >= 20
16
16
@@ -1442,3 +1442,54 @@ test('#3671 - Graceful close', async (t) => {
1442
1442
1443
1443
await t . completed
1444
1444
} )
1445
+
1446
+ test ( '#3803 - sending FormData bodies works' , async ( t ) => {
1447
+ const assert = tspl ( t , { plan : 4 } )
1448
+
1449
+ const server = createSecureServer ( pem ) . listen ( 0 )
1450
+ server . on ( 'stream' , async ( stream , headers ) => {
1451
+ const contentLength = Number ( headers [ 'content-length' ] )
1452
+
1453
+ assert . ok ( ! Number . isNaN ( contentLength ) )
1454
+ assert . ok ( headers [ 'content-type' ] ?. startsWith ( 'multipart/form-data; boundary=' ) )
1455
+
1456
+ stream . respond ( { ':status' : 200 } )
1457
+
1458
+ const fd = await new Response ( stream , {
1459
+ headers : {
1460
+ 'content-type' : headers [ 'content-type' ]
1461
+ }
1462
+ } ) . formData ( )
1463
+
1464
+ assert . deepEqual ( fd . get ( 'a' ) , 'b' )
1465
+ assert . deepEqual ( fd . get ( 'c' ) . name , 'e.fgh' )
1466
+
1467
+ stream . end ( )
1468
+ } )
1469
+
1470
+ await once ( server , 'listening' )
1471
+
1472
+ const client = new Client ( `https://localhost:${ server . address ( ) . port } ` , {
1473
+ connect : {
1474
+ rejectUnauthorized : false
1475
+ } ,
1476
+ allowH2 : true
1477
+ } )
1478
+
1479
+ t . after ( async ( ) => {
1480
+ server . close ( )
1481
+ await client . close ( )
1482
+ } )
1483
+
1484
+ const fd = new FormData ( )
1485
+ fd . set ( 'a' , 'b' )
1486
+ fd . set ( 'c' , new Blob ( [ 'd' ] ) , 'e.fgh' )
1487
+
1488
+ await client . request ( {
1489
+ path : '/' ,
1490
+ method : 'POST' ,
1491
+ body : fd
1492
+ } )
1493
+
1494
+ await assert . completed
1495
+ } )
0 commit comments