diff --git a/src/AspNetCore/Inc/protocolconfig.h b/src/AspNetCore/Inc/protocolconfig.h index 7cc0dc0..f7d915d 100644 --- a/src/AspNetCore/Inc/protocolconfig.h +++ b/src/AspNetCore/Inc/protocolconfig.h @@ -33,6 +33,12 @@ class PROTOCOL_CONFIG return m_msTimeout; } + BOOL + QueryPreserveHostHeader() const + { + return m_fPreserveHostHeader; + } + BOOL QueryReverseRewriteHeaders() const { @@ -84,6 +90,7 @@ class PROTOCOL_CONFIG private: BOOL m_fKeepAlive; + BOOL m_fPreserveHostHeader; BOOL m_fReverseRewriteHeaders; BOOL m_fIncludePortInXForwardedFor; diff --git a/src/AspNetCore/Src/forwardinghandler.cxx b/src/AspNetCore/Src/forwardinghandler.cxx index 5f4e316..39820d3 100644 --- a/src/AspNetCore/Src/forwardinghandler.cxx +++ b/src/AspNetCore/Src/forwardinghandler.cxx @@ -635,19 +635,21 @@ FORWARDING_HANDLER::GetHeaders( // this is wrong but Kestrel has dependency on it. // should change it in the future // - if (FAILED(hr = PATH::SplitUrl(pRequest->GetRawHttpRequest()->CookedUrl.pFullUrl, - &fSecure, - &struDestination, - &struUrl)) || - FAILED(hr = strTemp.CopyW(struDestination.QueryStr())) || - FAILED(hr = pRequest->SetHeader(HttpHeaderHost, - strTemp.QueryStr(), - static_cast(strTemp.QueryCCH()), - TRUE))) // fReplace - { - return hr; + if (!pProtocol->QueryPreserveHostHeader()) + { + if (FAILED(hr = PATH::SplitUrl(pRequest->GetRawHttpRequest()->CookedUrl.pFullUrl, + &fSecure, + &struDestination, + &struUrl)) || + FAILED(hr = strTemp.CopyW(struDestination.QueryStr())) || + FAILED(hr = pRequest->SetHeader(HttpHeaderHost, + strTemp.QueryStr(), + static_cast(strTemp.QueryCCH()), + TRUE))) // fReplace + { + return hr; + } } - // // Strip all headers starting with MS-ASPNETCORE. // These headers are generated by the asp.net core module and diff --git a/src/AspNetCore/Src/protocolconfig.cxx b/src/AspNetCore/Src/protocolconfig.cxx index 3f17e64..85fd86a 100644 --- a/src/AspNetCore/Src/protocolconfig.cxx +++ b/src/AspNetCore/Src/protocolconfig.cxx @@ -11,6 +11,7 @@ PROTOCOL_CONFIG::Initialize() m_fKeepAlive = TRUE; m_msTimeout = 120000; + m_fPreserveHostHeader = TRUE; m_fReverseRewriteHeaders = FALSE; if (FAILED(hr = m_strXForwardedForName.CopyW(L"X-Forwarded-For")))