@@ -443,30 +443,43 @@ var require_util = __commonJS({
443443 for ( let i = 0 ; i < headers . length ; i += 2 ) {
444444 const key = headers [ i ] . toString ( ) . toLowerCase ( ) ;
445445 let val = obj [ key ] ;
446- const encoding = key . length === 19 && key === "content-disposition" ? "latin1" : "utf8" ;
447446 if ( ! val ) {
448447 if ( Array . isArray ( headers [ i + 1 ] ) ) {
449448 obj [ key ] = headers [ i + 1 ] ;
450449 } else {
451- obj [ key ] = headers [ i + 1 ] . toString ( encoding ) ;
450+ obj [ key ] = headers [ i + 1 ] . toString ( "utf8" ) ;
452451 }
453452 } else {
454453 if ( ! Array . isArray ( val ) ) {
455454 val = [ val ] ;
456455 obj [ key ] = val ;
457456 }
458- val . push ( headers [ i + 1 ] . toString ( encoding ) ) ;
457+ val . push ( headers [ i + 1 ] . toString ( "utf8" ) ) ;
459458 }
460459 }
460+ if ( "content-length" in obj && "content-disposition" in obj ) {
461+ obj [ "content-disposition" ] = Buffer . from ( obj [ "content-disposition" ] ) . toString ( "latin1" ) ;
462+ }
461463 return obj ;
462464 }
463465 function parseRawHeaders ( headers ) {
464466 const ret = [ ] ;
467+ let hasContentLength = false ;
468+ let contentDispositionIdx = - 1 ;
465469 for ( let n = 0 ; n < headers . length ; n += 2 ) {
466470 const key = headers [ n + 0 ] . toString ( ) ;
467- const encoding = key . length === 19 && key . toLowerCase ( ) === "content-disposition" ? "latin1" : "utf8" ;
468- const val = headers [ n + 1 ] . toString ( encoding ) ;
469- ret . push ( key , val ) ;
471+ const val = headers [ n + 1 ] . toString ( "utf8" ) ;
472+ if ( key . length === 14 && ( key === "content-length" || key . toLowerCase ( ) === "content-length" ) ) {
473+ ret . push ( key , val ) ;
474+ hasContentLength = true ;
475+ } else if ( key . length === 19 && ( key === "content-disposition" || key . toLowerCase ( ) === "content-disposition" ) ) {
476+ contentDispositionIdx = ret . push ( key , val ) - 1 ;
477+ } else {
478+ ret . push ( key , val ) ;
479+ }
480+ }
481+ if ( hasContentLength && contentDispositionIdx !== - 1 ) {
482+ ret [ contentDispositionIdx ] = Buffer . from ( ret [ contentDispositionIdx ] ) . toString ( "latin1" ) ;
470483 }
471484 return ret ;
472485 }
@@ -1765,6 +1778,7 @@ var require_headers = __commonJS({
17651778 clear ( ) {
17661779 this [ kHeadersMap ] . clear ( ) ;
17671780 this [ kHeadersSortedMap ] = null ;
1781+ this . cookies = null ;
17681782 }
17691783 append ( name , value ) {
17701784 this [ kHeadersSortedMap ] = null ;
0 commit comments