Skip to content

New Request Feature to delegate request to other request queues #21163

@shirhatti

Description

@shirhatti

Let's add a request feature IHttpSysRequestTransferFeature to transfer requests to other Http.Sys request queues.

namespace Microsoft.AspNetCore.Server.HttpSys
{
    public class DelegationRule : IDisposable
    {
        public string QueueName { get; }
        public string UrlPrefix { get; }
    }
}
namespace Microsoft.AspNetCore.Server.HttpSys
{
    public interface IHttpSysRequestTransferFeature
    {
        bool IsTransferable { get; }
        void TransferRequest(DelegationRule destination);
    }
}
namespace Microsoft.AspNetCore.Server.HttpSys
{
    public interface IServerDelegationFeature
    {
        DelegationRule CreateDelegationRule(string queueName, string urlPrefix);
    }
}

Sample API usage:

namespace Sample
{
    public class Startup
    {
        private DelegationRule _delegationRule;

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            
            var delegator = app.ServerFeatures.Get<IServerDelegationFeature>();
            _delegationRule = delegator.CreateDelegationRule("DefaultAppPool", "http://*:80/");

            app.Run(context =>
            {
                var transferFeature = context.Features.Get<IHttpSysRequestTransferFeature>();
                transferFeature.TransferRequest(_delegationRule);
                return Task.CompletedTask;
            });

            lifetime.ApplicationStopped.Register(() => _delegationRule.Dispose());
        }
    }
}

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-httpsys

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions