Commit 9aa639b 1 parent 25c3230 commit 9aa639b Copy full SHA for 9aa639b
File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,7 @@ class Request {
182
182
this . headers += `content-type: ${ contentType } \r\n`
183
183
}
184
184
this . body = bodyStream . stream
185
+ this . contentLength = bodyStream . length
185
186
} else if ( util . isBlobLike ( body ) && this . contentType == null && body . type ) {
186
187
this . contentType = body . type
187
188
this . headers += `content-type: ${ body . type } \r\n`
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const { test, skip } = require ( 'tap' )
4
+ const { nodeMajor, nodeMinor } = require ( '../lib/core/util' )
5
+ const { createServer } = require ( 'http' )
6
+ const { once } = require ( 'events' )
7
+ const { File, FormData, request } = require ( '..' )
8
+
9
+ if ( nodeMajor < 16 || ( nodeMajor === 16 && nodeMinor < 8 ) ) {
10
+ skip ( 'FormData is not available in node < v16.8.0' )
11
+ process . exit ( )
12
+ }
13
+
14
+ test ( 'undici.request with a FormData body should set content-length header' , async ( t ) => {
15
+ const server = createServer ( ( req , res ) => {
16
+ t . ok ( req . headers [ 'content-length' ] )
17
+ res . end ( )
18
+ } ) . listen ( 0 )
19
+
20
+ t . teardown ( server . close . bind ( server ) )
21
+ await once ( server , 'listening' )
22
+
23
+ const body = new FormData ( )
24
+ body . set ( 'file' , new File ( [ 'abc' ] , 'abc.txt' ) )
25
+
26
+ await request ( `http://localhost:${ server . address ( ) . port } ` , {
27
+ method : 'POST' ,
28
+ body
29
+ } )
30
+ } )
You can’t perform that action at this time.
0 commit comments