Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
avoid some allocs
  • Loading branch information
BrennanConroy committed Dec 6, 2024
commit e36d998456dcad050835702e857e764bddc94588
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,15 @@ private void ValidateNonOriginHostHeader(string hostText)
// authority component, excluding any userinfo subcomponent and its "@"
// delimiter.

// Accessing authority always allocates, store it in a local to only allocate once
var authority = _absoluteRequestTarget!.Authority;

// System.Uri doesn't not tell us if the port was in the original string or not.
// When IsDefaultPort = true, we will allow Host: with or without the default port
if (hostText != _absoluteRequestTarget!.Authority)
if (hostText != authority)
{
if (!_absoluteRequestTarget.IsDefaultPort
|| hostText != $"{_absoluteRequestTarget.Authority}:{_absoluteRequestTarget.Port}")
|| hostText != $"{authority}:{_absoluteRequestTarget.Port}")
{
if (_context.ServiceContext.ServerOptions.AllowHostHeaderOverride)
{
Expand All @@ -657,7 +660,7 @@ private void ValidateNonOriginHostHeader(string hostText)
// see: https://datatracker.ietf.org/doc/html/rfc2616/#section-14.23
// A "host" without any trailing port information implies the default
// port for the service requested (e.g., "80" for an HTTP URL).
hostText = _absoluteRequestTarget.Authority;
hostText = authority;
HttpRequestHeaders.HeaderHost = hostText;
}
else
Expand Down
Loading