Skip to content

Support adding and removing Kestrel endpoints with code #21244

Open
@halter73

Description

@halter73

Is your feature request related to a problem? Please describe.

This is a followup to #19376. Kestrel should support a programmatic API for adding and removing endpoints with code in addition to config.

For reference, here's how it looks with HttpSys:

public HttpSysOptions ServerOptions { get; set; }
public void Configure(IApplicationBuilder app)
{
var addresses = ServerOptions.UrlPrefixes;
addresses.Add("http://localhost:12346/pathBase/");
app.Use(async (context, next) =>
{
// Note: To add any prefix other than localhost you must run this sample as an administrator.
var toAdd = context.Request.Query["add"];
if (!string.IsNullOrEmpty(toAdd))
{
context.Response.ContentType = "text/html";
await context.Response.WriteAsync("<html><body>");
try
{
addresses.Add(toAdd);

Describe the solution you'd like

We should probably have APIs similar to KestrelServerOptions.Listen* that work even after the server has started. We'll also need an API to query active endpoints and remove them. Perhaps IServerAddressesFeature could be leveraged for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-fewThis issue impacts only small number of customersapi-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-kestrelfeature-yarpThis issue is related to work on yarpseverity-nice-to-haveThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions