Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for endpoints defined in Kestrel config #4205

Merged
merged 16 commits into from
Jun 3, 2024
Merged
Prev Previous commit
Next Next commit
rename KestrelConfiguration -> Configuration
  • Loading branch information
davidebbo committed May 30, 2024
commit 32b015446f3579fe3352cbe731610242386320e3
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/IProjectMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IProjectMetadata : IResourceAnnotation

// These are for testing
internal LaunchSettings? LaunchSettings => null;
internal IConfiguration? KestrelConfiguration => null;
internal IConfiguration? Configuration => null;
}

[DebuggerDisplay("Type = {GetType().Name,nq}, ProjectPath = {ProjectPath}")]
Expand Down
12 changes: 6 additions & 6 deletions src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ private static IResourceBuilder<ProjectResource> WithProjectDefaults(this IResou
builder.WithAnnotation(new LaunchProfileAnnotation(launchProfileName));
}

var kestrelConfig = GetKestrelConfiguration(projectResource);
var kestrelEndpoints = kestrelConfig.GetSection("Kestrel:Endpoints").GetChildren();
var config = GetConfiguration(projectResource);
davidebbo marked this conversation as resolved.
Show resolved Hide resolved
var kestrelEndpoints = config.GetSection("Kestrel:Endpoints").GetChildren();
var launchProfile = projectResource.GetEffectiveLaunchProfile(throwIfNotFound: true);

// Get all the Kestrel configuration endpoint bindings, grouped by scheme
Expand All @@ -239,7 +239,7 @@ private static IResourceBuilder<ProjectResource> WithProjectDefaults(this IResou
.GroupBy(entry => entry.BindingAddress.Scheme);

// Helper to change the transport to http2 if needed
var isHttp2ConfiguredInAppSettings = kestrelConfig["Kestrel:EndpointDefaults:Protocols"] == "Http2";
var isHttp2ConfiguredInAppSettings = config["Kestrel:EndpointDefaults:Protocols"] == "Http2";
var adjustTransport = (EndpointAnnotation e) => e.Transport = isHttp2ConfiguredInAppSettings ? "http2" : e.Transport;

if (builder.ApplicationBuilder.ExecutionContext.IsRunMode)
Expand Down Expand Up @@ -401,14 +401,14 @@ public static IResourceBuilder<ProjectResource> DisableForwardedHeaders(this IRe
return builder;
}

private static IConfiguration GetKestrelConfiguration(ProjectResource projectResource)
private static IConfiguration GetConfiguration(ProjectResource projectResource)
{
var projectMetadata = projectResource.GetProjectMetadata();

// For testing
if (projectMetadata.KestrelConfiguration is { } kestrelConfiguration)
if (projectMetadata.Configuration is { } configuration)
{
return kestrelConfiguration;
return configuration;
}

var projectDirectoryPath = Path.GetDirectoryName(projectMetadata.ProjectPath)!;
Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Tests/ProjectResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private sealed class TestProjectWithKestrelConfig : IProjectMetadata
{
public string ProjectPath => "projectC";
public LaunchSettings LaunchSettings { get; } = new();
public IConfiguration KestrelConfiguration
public IConfiguration Configuration
{
get
{
Expand Down