Skip to content
Merged
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ internal static ListenOptions ParseAddress(string address, out bool https)

return options;

bool IsLocalhost(string host, out string? prefix)
static bool IsLocalhost(string host, out string? prefix)
{
// Check for "localhost"
if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase))
if (string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase))
{
prefix = null;
return true;
}

// Check for use of .localhost TLD (Top Level Domain)
if (host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(parsedAddress.Host, ".localhost", StringComparison.OrdinalIgnoreCase))
const string localhostTld = ".localhost";
if (host.Length > localhostTld.Length && host.EndsWith(localhostTld, StringComparison.OrdinalIgnoreCase))
{
// Take all but the .localhost TLD as the prefix
prefix = host[..^10]; // 10 is the length of ".localhost"
prefix = host[..^localhostTld.Length];
return true;
}

Expand Down
Loading