File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,6 +254,15 @@ function requestAsEventEmitter(opts) {
254254 Promise . resolve ( getBodySize ( opts ) )
255255 . then ( size => {
256256 uploadBodySize = size ;
257+
258+ if (
259+ is . undefined ( opts . headers [ 'content-length' ] ) &&
260+ is . undefined ( opts . headers [ 'transfer-encoding' ] ) &&
261+ isFormData ( opts . body )
262+ ) {
263+ opts . headers [ 'content-length' ] = size ;
264+ }
265+
257266 get ( opts ) ;
258267 } )
259268 . catch ( err => {
Original file line number Diff line number Diff line change @@ -105,6 +105,14 @@ test('form-data automatic content-type', async t => {
105105 t . is ( headers [ 'content-type' ] , `multipart/form-data; boundary=${ form . getBoundary ( ) } ` ) ;
106106} ) ;
107107
108+ test ( 'form-data sets content-length' , async t => {
109+ const form = new FormData ( ) ;
110+ form . append ( 'a' , 'b' ) ;
111+ const { body} = await got ( s . url , { body : form } ) ;
112+ const headers = JSON . parse ( body ) ;
113+ t . is ( headers [ 'content-length' ] , '157' ) ;
114+ } ) ;
115+
108116test ( 'remove null value headers' , async t => {
109117 const headers = ( await got ( s . url , {
110118 headers : {
You can’t perform that action at this time.
0 commit comments