@@ -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
@@ -1642,3 +1642,54 @@ test('#3753 - Handle GOAWAY Gracefully', async (t) => {
1642
1642
1643
1643
await t . completed
1644
1644
} )
1645
+
1646
+ test ( '#3803 - sending FormData bodies works' , async ( t ) => {
1647
+ const assert = tspl ( t , { plan : 4 } )
1648
+
1649
+ const server = createSecureServer ( pem ) . listen ( 0 )
1650
+ server . on ( 'stream' , async ( stream , headers ) => {
1651
+ const contentLength = Number ( headers [ 'content-length' ] )
1652
+
1653
+ assert . ok ( ! Number . isNaN ( contentLength ) )
1654
+ assert . ok ( headers [ 'content-type' ] ?. startsWith ( 'multipart/form-data; boundary=' ) )
1655
+
1656
+ stream . respond ( { ':status' : 200 } )
1657
+
1658
+ const fd = await new Response ( stream , {
1659
+ headers : {
1660
+ 'content-type' : headers [ 'content-type' ]
1661
+ }
1662
+ } ) . formData ( )
1663
+
1664
+ assert . deepEqual ( fd . get ( 'a' ) , 'b' )
1665
+ assert . deepEqual ( fd . get ( 'c' ) . name , 'e.fgh' )
1666
+
1667
+ stream . end ( )
1668
+ } )
1669
+
1670
+ await once ( server , 'listening' )
1671
+
1672
+ const client = new Client ( `https://localhost:${ server . address ( ) . port } ` , {
1673
+ connect : {
1674
+ rejectUnauthorized : false
1675
+ } ,
1676
+ allowH2 : true
1677
+ } )
1678
+
1679
+ t . after ( async ( ) => {
1680
+ server . close ( )
1681
+ await client . close ( )
1682
+ } )
1683
+
1684
+ const fd = new FormData ( )
1685
+ fd . set ( 'a' , 'b' )
1686
+ fd . set ( 'c' , new Blob ( [ 'd' ] ) , 'e.fgh' )
1687
+
1688
+ await client . request ( {
1689
+ path : '/' ,
1690
+ method : 'POST' ,
1691
+ body : fd
1692
+ } )
1693
+
1694
+ await assert . completed
1695
+ } )
0 commit comments