Skip to content

UseUrls equivilant API for Http and Https ports #44772

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

Open
Tratcher opened this issue Oct 27, 2022 · 2 comments
Open

UseUrls equivilant API for Http and Https ports #44772

Tratcher opened this issue Oct 27, 2022 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Needs: Design This issue requires design work before implementating.
Milestone

Comments

@Tratcher
Copy link
Member

Tratcher commented Oct 27, 2022

Background and Motivation

#44194 added config support in the host for mapping HTTP_PORTS and HTTPS_PORTS to URLS. @davidfowl suggested also adding an API for this on the host, similar to UseUrls.

#43135 (comment)

Proposed API

Initial theories, needs work:

namespace Microsoft.AspNetCore.Hosting;

public static class HostingAbstractionsWebHostBuilderExtensions
{
+    public static IWebHostBuilder UseHttpPorts(this IWebHostBuilder hostBuilder, params int[] httpPorts);
+    public static IWebHostBuilder UseHttpsPorts(this IWebHostBuilder hostBuilder, params int[] httpsPorts);
+    public static IWebHostBuilder UsePort(this IWebHostBuilder hostBuilder, int port, bool useHttps);
+    public static IWebHostBuilder UsePorts(this IWebHostBuilder hostBuilder, int httpPort, int httpsPort);
}

Usage Examples

var port = int.Parse(Environment.GetEnvironmentVariable("PORT") ?? "3000");

var builder = WebApplication.CreateBuilder(args);

buider.WebHost.UsePort(port);

var app = builder.Build();

app.MapGet("/", () => "Hello World");

app.Run();

Alternative Designs

Risks

@Tratcher Tratcher added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-runtime labels Oct 27, 2022
@davidfowl
Copy link
Member

I added a usage sample. UsePort should have useHttps = false.

@adityamandaleeka adityamandaleeka added this to the .NET 8 Planning milestone Oct 31, 2022
@adityamandaleeka adityamandaleeka added the Needs: Design This issue requires design work before implementating. label Oct 31, 2022
@adityamandaleeka
Copy link
Member

We're not super happy with the current shape of this yet... need to spend some time to get it right.

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@amcasey amcasey modified the milestones: .NET 8 Planning, Backlog Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Needs: Design This issue requires design work before implementating.
Projects
None yet
Development

No branches or pull requests

5 participants