@@ -573,7 +573,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
573
573
const completedRequest = await waitForCompletedRequest ( clientReq ) ;
574
574
const modifiedReq = await this . beforeRequest ( {
575
575
...completedRequest ,
576
- headers : _ . cloneDeep ( completedRequest . headers ) ,
576
+ headers : _ . cloneDeep ( rawHeadersToObject ( completedRequest . rawHeaders ) ) ,
577
577
rawHeaders : _ . cloneDeep ( completedRequest . rawHeaders )
578
578
} ) ;
579
579
@@ -597,16 +597,18 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
597
597
reqUrl = modifiedReq ?. url || reqUrl ;
598
598
599
599
headersManuallyModified = ! ! modifiedReq ?. headers ;
600
- let headers = modifiedReq ?. headers || clientReq . headers ;
601
-
602
- Object . assign ( headers ,
603
- isH2Downstream
604
- ? getH2HeadersAfterModification ( reqUrl , clientReq . headers , modifiedReq ?. headers )
605
- : { 'host' : getHostAfterModification ( reqUrl , clientReq . headers , modifiedReq ?. headers ) }
606
- ) ;
600
+ const clientHeaders = rawHeadersToObject ( clientReq . rawHeaders )
601
+ let headers = modifiedReq ?. headers || clientHeaders ;
602
+ if ( ! this . forwarding || this . forwarding . updateHostHeader === false ) {
603
+ Object . assign ( headers ,
604
+ isH2Downstream
605
+ ? getH2HeadersAfterModification ( reqUrl , clientHeaders , modifiedReq ?. headers )
606
+ : { 'host' : getHostAfterModification ( reqUrl , clientHeaders , modifiedReq ?. headers ) }
607
+ ) ;
608
+ }
607
609
608
610
validateCustomHeaders (
609
- clientReq . headers ,
611
+ clientHeaders ,
610
612
modifiedReq ?. headers ,
611
613
OVERRIDABLE_REQUEST_PSEUDOHEADERS // These are handled by getCorrectPseudoheaders above
612
614
) ;
@@ -617,7 +619,7 @@ export class PassThroughHandler extends PassThroughHandlerDefinition {
617
619
// Automatically match the content-length to the body, unless it was explicitly overriden.
618
620
headers [ 'content-length' ] = getContentLengthAfterModification (
619
621
reqBodyOverride ,
620
- clientReq . headers ,
622
+ clientHeaders ,
621
623
modifiedReq ?. headers
622
624
) ;
623
625
}
0 commit comments