@@ -443,30 +443,43 @@ var require_util = __commonJS({
443
443
for ( let i = 0 ; i < headers . length ; i += 2 ) {
444
444
const key = headers [ i ] . toString ( ) . toLowerCase ( ) ;
445
445
let val = obj [ key ] ;
446
- const encoding = key . length === 19 && key === "content-disposition" ? "latin1" : "utf8" ;
447
446
if ( ! val ) {
448
447
if ( Array . isArray ( headers [ i + 1 ] ) ) {
449
448
obj [ key ] = headers [ i + 1 ] ;
450
449
} else {
451
- obj [ key ] = headers [ i + 1 ] . toString ( encoding ) ;
450
+ obj [ key ] = headers [ i + 1 ] . toString ( "utf8" ) ;
452
451
}
453
452
} else {
454
453
if ( ! Array . isArray ( val ) ) {
455
454
val = [ val ] ;
456
455
obj [ key ] = val ;
457
456
}
458
- val . push ( headers [ i + 1 ] . toString ( encoding ) ) ;
457
+ val . push ( headers [ i + 1 ] . toString ( "utf8" ) ) ;
459
458
}
460
459
}
460
+ if ( "content-length" in obj && "content-disposition" in obj ) {
461
+ obj [ "content-disposition" ] = Buffer . from ( obj [ "content-disposition" ] ) . toString ( "latin1" ) ;
462
+ }
461
463
return obj ;
462
464
}
463
465
function parseRawHeaders ( headers ) {
464
466
const ret = [ ] ;
467
+ let hasContentLength = false ;
468
+ let contentDispositionIdx = - 1 ;
465
469
for ( let n = 0 ; n < headers . length ; n += 2 ) {
466
470
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" ) ;
470
483
}
471
484
return ret ;
472
485
}
@@ -1765,6 +1778,7 @@ var require_headers = __commonJS({
1765
1778
clear ( ) {
1766
1779
this [ kHeadersMap ] . clear ( ) ;
1767
1780
this [ kHeadersSortedMap ] = null ;
1781
+ this . cookies = null ;
1768
1782
}
1769
1783
append ( name , value ) {
1770
1784
this [ kHeadersSortedMap ] = null ;
0 commit comments