@@ -162,7 +162,7 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
162162 // custom header specified (as string)?
163163 // it becomes responsible for boundary
164164 // (e.g. to handle extra CRLFs on .NET servers)
165- if ( options . header ) {
165+ if ( typeof options . header == 'string' ) {
166166 return options . header ;
167167 }
168168
@@ -177,9 +177,28 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
177177 'Content-Type' : [ ] . concat ( contentType || [ ] )
178178 } ;
179179
180+ // allow custom headers.
181+ if ( typeof options . header == 'object' ) {
182+ populate ( headers , options . header ) ;
183+ }
184+
185+ var header ;
180186 for ( var prop in headers ) {
181- if ( headers [ prop ] . length ) {
182- contents += prop + ': ' + headers [ prop ] . join ( '; ' ) + FormData . LINE_BREAK ;
187+ header = headers [ prop ] ;
188+
189+ // skip nullish headers.
190+ if ( header == null ) {
191+ continue ;
192+ }
193+
194+ // convert all headers to arrays.
195+ if ( ! Array . isArray ( header ) ) {
196+ header = [ header ] ;
197+ }
198+
199+ // add non-empty headers.
200+ if ( header . length ) {
201+ contents += prop + ': ' + header . join ( '; ' ) + FormData . LINE_BREAK ;
183202 }
184203 }
185204
@@ -192,7 +211,8 @@ FormData.prototype._getContentDisposition = function(value, options) {
192211
193212 // custom filename takes precedence
194213 // fs- and request- streams have path property
195- var filename = options . filename || value . path ;
214+ // formidable and the browser add a name property.
215+ var filename = options . filename || value . name || value . path ;
196216
197217 // or try http response
198218 if ( ! filename && value . readable && value . hasOwnProperty ( 'httpVersion' ) ) {
@@ -211,6 +231,11 @@ FormData.prototype._getContentType = function(value, options) {
211231 // use custom content-type above all
212232 var contentType = options . contentType ;
213233
234+ // or try `name` from formidable, browser
235+ if ( ! contentType && value . name ) {
236+ contentType = mime . lookup ( value . name ) ;
237+ }
238+
214239 // or try `path` from fs-, request- streams
215240 if ( ! contentType && value . path ) {
216241 contentType = mime . lookup ( value . path ) ;
0 commit comments