Skip to content

Conversation

@DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Jul 3, 2025

Description

Adds urls for *.localhost and other localhost adjacent bindings.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 3, 2025
@BrennanConroy BrennanConroy force-pushed the damianedwards/non-localhost-urls branch from 222cddc to 039f225 Compare July 11, 2025 19:50
@BrennanConroy BrennanConroy marked this pull request as ready for review July 11, 2025 20:27
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 20:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for generating and testing URLs for *.localhost subdomains and hosts that bind to multiple addresses.

  • Added tests to verify URL annotations include both localhost and custom .localhost domains, and machine-name URLs for non-localhost hosts.
  • Updated ApplicationOrchestrator to emit extra ResourceUrlAnnotation entries when an endpoint is bound to multiple addresses or a .localhost subdomain.
  • Enhanced DcpExecutor.NormalizeTargetHost to treat any *.localhost host as localhost with a single-address binding.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/Aspire.Hosting.Tests/WithEndpointTests.cs New tests validating URL annotations for .localhost domains and multi-address hosts.
src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs Adds logic to append extra URLs for multi-address bindings and .localhost subdomains.
src/Aspire.Hosting/Dcp/DcpExecutor.cs Normalizes *.localhost hosts to localhost with single-address binding.
Comments suppressed due to low confidence (1)

tests/Aspire.Hosting.Tests/WithEndpointTests.cs:652

  • The tests for non-localhost hosts currently cover IPv4 (0.0.0.0) but the IPv6 case is commented out. Consider adding a reliable assertion or skipping strategy for IPv6 (::) to ensure coverage across both IP versions.
    [Theory]

var endpointReference = new EndpointReference(resourceWithEndpoints, endpoint);
var url = new ResourceUrlAnnotation { Url = allocatedEndpoint.UriString, Endpoint = endpointReference };
urls.Add(url);
if (allocatedEndpoint.BindingMode != EndpointBindingMode.SingleAddress && (endpoint.TargetHost is not "localhost" or "127.0.0.1"))
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check on endpoint.TargetHost.Length elsewhere uses a magic number (10) to detect .localhost domains. Rather than relying on string length, consider using EndsWith(".localhost", StringComparison.OrdinalIgnoreCase) by itself or extracting the suffix into a named constant for clarity.

Copilot uses AI. Check for mistakes.

{
null or "" => ("localhost", EndpointBindingMode.SingleAddress), // Default is localhost
var s when string.Equals(s, "localhost", StringComparison.OrdinalIgnoreCase) => ("localhost", EndpointBindingMode.SingleAddress), // Explicitly set to localhost
var s when s.Length > 10 && s.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase) => ("localhost", EndpointBindingMode.SingleAddress), // Explicitly set to localhost when using .localhost subdomain
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length check (s.Length > 10) is redundant because EndsWith(".localhost") already implies a minimum length. Consider removing the length condition or defining a clear constant for the subdomain suffix to improve readability.

Suggested change
var s when s.Length > 10 && s.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase) => ("localhost", EndpointBindingMode.SingleAddress), // Explicitly set to localhost when using .localhost subdomain
var s when s.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase) => ("localhost", EndpointBindingMode.SingleAddress), // Explicitly set to localhost when using .localhost subdomain

Copilot uses AI. Check for mistakes.

Copy link
Member

@danegsta danegsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@DamianEdwards
Copy link
Member Author

/backport to release/9.4

@github-actions
Copy link
Contributor

@DamianEdwards DamianEdwards merged commit 04fc33c into main Jul 14, 2025
544 of 546 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/non-localhost-urls branch July 14, 2025 20:23
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants