Skip to content

Commit 1c3f7ff

Browse files
author
ladeak
committed
Refactor IsLocalhost to static method
Changed `IsLocalhost` from an instance method to a static method. Updated the parameter to use `host` directly instead of `parsedAddress.Host`. Modified the check for the `.localhost` TLD to ensure the host length is greater than 10, optimizing the condition to avoid unnecessary checks for shorter hostnames. Fixes #61155
1 parent e14a8ff commit 1c3f7ff

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Servers/Kestrel/Core/src/Internal/AddressBinder.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,16 @@ internal static ListenOptions ParseAddress(string address, out bool https)
142142

143143
return options;
144144

145-
bool IsLocalhost(string host, out string? prefix)
145+
static bool IsLocalhost(string host, out string? prefix)
146146
{
147147
// Check for "localhost"
148-
if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase))
148+
if (string.Equals(host, "localhost", StringComparison.OrdinalIgnoreCase))
149149
{
150150
prefix = null;
151151
return true;
152152
}
153153

154-
// Check for use of .localhost TLD (Top Level Domain)
155-
if (host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase)
156-
&& !string.Equals(parsedAddress.Host, ".localhost", StringComparison.OrdinalIgnoreCase))
154+
if (host.Length > 10 && host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase))
157155
{
158156
// Take all but the .localhost TLD as the prefix
159157
prefix = host[..^10]; // 10 is the length of ".localhost"

0 commit comments

Comments
 (0)