Skip to content

Commit a8c389b

Browse files
Do not set host if it's not explicitely set in config (#6862)
1 parent 3294486 commit a8c389b

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

src/Libraries/Microsoft.Extensions.ServiceDiscovery.Yarp/ServiceDiscoveryDestinationResolver.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,13 @@ public async ValueTask<ResolvedDestinationCollection> ResolveDestinationsAsync(I
8989
}
9090

9191
var name = $"{originalName}[{addressString}]";
92-
string? resolvedHost;
92+
string? resolvedHost = null;
9393

9494
// Use the configured 'Host' value if it is provided.
9595
if (!string.IsNullOrEmpty(originalConfig.Host))
9696
{
9797
resolvedHost = originalConfig.Host;
9898
}
99-
else if (uri.IsLoopback)
100-
{
101-
// If there is no configured 'Host' value and the address resolves to localhost, do not set a host.
102-
// This is to account for non-wildcard development certificate.
103-
resolvedHost = null;
104-
}
105-
else
106-
{
107-
// Excerpt from RFC 9110 Section 7.2: The "Host" header field in a request provides the host and port information from the target URI [...]
108-
// See: https://www.rfc-editor.org/rfc/rfc9110.html#field.host
109-
// i.e, use Authority and not Host.
110-
resolvedHost = originalUri.Authority;
111-
}
11299

113100
var config = originalConfig with { Host = resolvedHost, Address = resolvedAddress, Health = healthAddress };
114101
results.Add((name, config));

test/Libraries/Microsoft.Extensions.ServiceDiscovery.Yarp.Tests/YarpServiceDiscoveryTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ public async Task ServiceDiscoveryDestinationResolverTests_Configuration_Host_Va
188188
}
189189
else
190190
{
191-
// For non-localhost values, fallback to the input address.
192-
Assert.Equal("basket", a.Host);
191+
Assert.Null(a.Host);
193192
}
194193
});
195194
}

0 commit comments

Comments
 (0)