Skip to content

Ensure WithHostHttpsPort works when chained inline#13623

Merged
danegsta merged 2 commits intodotnet:mainfrom
danegsta:danegsta/yarpHttps
Dec 21, 2025
Merged

Ensure WithHostHttpsPort works when chained inline#13623
danegsta merged 2 commits intodotnet:mainfrom
danegsta:danegsta/yarpHttps

Conversation

@danegsta
Copy link
Member

Description

Fixes an issue where .WithHostHttpsPort wouldn't work due to the HTTPS endpoint being created in BeforeStartEvent.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 18, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13623

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13623"

@danegsta danegsta changed the title Ensure WithHostHttpsPort works outside when chained inline Ensure WithHostHttpsPort works when chained inline Dec 18, 2025
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

This PR fixes a timing issue where calling .WithHostHttpsPort() inline didn't work properly because the HTTPS endpoint was being created later in the BeforeStartEvent. The solution stores the desired host HTTPS port in the YarpResource and applies it when the HTTPS endpoint is created.

Key Changes:

  • Introduced a new HostHttpsPort property on YarpResource to defer port assignment until endpoint creation
  • Modified WithHostHttpsPort to store the port value instead of attempting to modify a potentially non-existent endpoint
  • Updated the BeforeStartEvent handler to use the stored HostHttpsPort value when creating the HTTPS endpoint
  • Added comprehensive test coverage for both successful and unsuccessful scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Hosting.Yarp/YarpResource.cs Added HostHttpsPort property to store the desired HTTPS host port until the endpoint is created
src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs Simplified WithHostHttpsPort to store port value on resource; updated BeforeStartEvent handler to apply stored port when creating HTTPS endpoint
tests/Aspire.Hosting.Yarp.Tests/AddYarpTests.cs Added two test cases validating that WithHostHttpsPort works correctly when HTTPS is configured and is ignored when HTTPS is not configured

@Kralizek
Copy link

Thanks for the quick work on the issue!

@halllo
Copy link

halllo commented Dec 21, 2025

I think I have the same issue #13674.

@halllo
Copy link

halllo commented Dec 21, 2025

Do you know if there is a workaround available? Would be helpful to mitigate the issue until this is approved and merged.

@halllo
Copy link

halllo commented Dec 21, 2025

I built my own workaround inlining the resource registration:

var gateway = builder
                     //.AddYarp("Gateway")
                     //.WithHttpsEndpoint(8443)
                     .AddYarpWithHttpsHostPort("Gateway", 8443)
                     .WithHostPort(8080)

@danegsta
Copy link
Member Author

danegsta commented Dec 21, 2025

I built my own workaround inlining the resource registration:

var gateway = builder
                     //.AddYarp("Gateway")
                     //.WithHttpsEndpoint(8443)
                     .AddYarpWithHttpsHostPort("Gateway", 8443)
                     .WithHostPort(8080)

The other workaround is to use a BeforeStartEvent handler (for timing reasons it has to be registered after the YARP resource is created):

var gateway = builder.AddYarp("gateway");

builder.Eventing.Subscribe<BeforeStartEvent>((_, _) =>
{
    gateway.WithHostHttpsPort(8443);
    return Task.CompletedTask;
});

@danegsta danegsta merged commit e703a9e into dotnet:main Dec 21, 2025
1114 of 1123 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Dec 21, 2025
@danegsta
Copy link
Member Author

/backport to release/13.1

@github-actions
Copy link
Contributor

Started backporting to release/13.1: https://github.com/dotnet/aspire/actions/runs/20417545148

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants