File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -458,10 +458,17 @@ function normalizeArguments(url, opts) {
458458 opts
459459 ) ;
460460
461+ const headers = lowercaseKeys ( opts . headers ) ;
462+ for ( const key of Object . keys ( headers ) ) {
463+ if ( headers [ key ] === null || headers [ key ] === undefined ) {
464+ delete headers [ key ] ;
465+ }
466+ }
467+
461468 opts . headers = Object . assign ( {
462469 'user-agent' : `${ pkg . name } /${ pkg . version } (https://github.com/sindresorhus/got)` ,
463470 'accept-encoding' : 'gzip,deflate'
464- } , lowercaseKeys ( opts . headers ) ) ;
471+ } , headers ) ;
465472
466473 const query = opts . query ;
467474
Original file line number Diff line number Diff line change @@ -89,6 +89,24 @@ test('form-data automatic content-type', async t => {
8989 t . is ( headers [ 'content-type' ] , `multipart/form-data; boundary=${ form . getBoundary ( ) } ` ) ;
9090} ) ;
9191
92+ test ( 'remove null value headers' , async t => {
93+ const headers = ( await got ( s . url , {
94+ headers : {
95+ unicorns : null
96+ }
97+ } ) ) . body ;
98+ t . false ( Object . prototype . hasOwnProperty . call ( headers , 'unicorns' ) ) ;
99+ } ) ;
100+
101+ test ( 'remove undefined value headers' , async t => {
102+ const headers = ( await got ( s . url , {
103+ headers : {
104+ unicorns : undefined
105+ }
106+ } ) ) . body ;
107+ t . false ( Object . prototype . hasOwnProperty . call ( headers , 'unicorns' ) ) ;
108+ } ) ;
109+
92110test . after ( 'cleanup' , async ( ) => {
93111 await s . close ( ) ;
94112} ) ;
You can’t perform that action at this time.
0 commit comments