Skip to content

New Kestrel endpoint configuration API #212

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
halter73 opened this issue Jan 11, 2017 · 0 comments
Open

New Kestrel endpoint configuration API #212

halter73 opened this issue Jan 11, 2017 · 0 comments

Comments

@halter73
Copy link
Member

For right now, there is no change in the behavior of the WebHostBuilder extension method .UseUrls() as long as UseHttps() nor any other IConnectionFilter is configured.

The main breaking change is that KestrelServerOptions.ConnectionFilter has been removed and replaced with ListenOptions.ConnectionAdapters. Since connection filters are no longer global, but instead per-endpoint, the IConnectionFilter interface has been removed and replaced with IConnectionAdapter. The entire Microsoft.AspNetCore.Server.Kestrel.Filter namespace has been removed and replaced with the Microsoft.AspNetCore.Server.Kestrel.Adapter namespace.

This means that any extension methods that add a global connection filter to KestrelServerOptions (namely UseHttps() and UseConnectionLogging()) are now ListenOptions extension methods.

The second breaking change is that KestrelServerOptions.NoDelay has been moved to ListenOptions.NoDelay.


The following description of the new Kestrel endpoint configuration API mostly comes from aspnet/KestrelHttpServer#996.

  • Added an extension method to KestrelServerOptions for binding to a TCP socket. There is no overload on .Listen() that allows you to configure an SSL cert without using an options lambda.
var host = new WebHostBuilder()
            .UseKestrel(options =>
            {
                // Easy mode (http only)
                options.Listen(IPAddress.Any, 80);

                // Verbose
                options.Listen(IPAddress.Any, 443, listenOptions => 
                {
                    listenOptions.NoDelay = false;
                    // Enable https
                    listenOptions.UseHttps("server.pfx");
                });
            })
            .UseStartup<Startup>()
            .Build();

host.Run();
  • Added an extension method to KestrelServerOptions for binding to a unix socket. There is no overload on .ListenUnixSocket() that allows you to configure an SSL cert without using an options lambda.
var host = new WebHostBuilder()
            .UseKestrel(options =>
            {
                // Easy mode
                options.ListenUnixSocket("/tmp/kestrel-test.sock");

                // Verbose
                options.ListenUnixSocket("/tmp/kestrel-test.sock", listenOptions => 
                {
                    listenOptions.UseHttps("server.pfx");
                });
            })
            .UseStartup<Startup>()
            .Build();

host.Run();
  • Added an extension method to KestrelServerOptions for binding to a file descriptor. There is no overload on .ListenHandle() that allows you to configure an SSL cert without using an options lambda.
var host = new WebHostBuilder()
            .UseKestrel(options =>
            {
                var fds = Environment.GetEnvironment("SD_LISTEN_FDS_START");
                int fd = Int32.Parse(fds);

                // Easy mode
                options.ListenHandle(fd);

                // Verbose
                options.ListenHandle(fd, listenOptions => 
                {
                    listenOptions.UseHttps("server.pfx");
                });
            })
            .UseStartup<Startup>()
            .Build();
host.Run();
  • Given that the file descriptor will be used will oftentimes be used with systemd socket activation (Support systemd socket activation KestrelHttpServer#1057), provide an extension method to KestrelServerOptions that parses the environment variable set by systemd and binds to that file descriptor. This method will no-op if the requisite environment variable has not been set (Similar to how .UseIISIntegration() no-ops).
var host = new WebHostBuilder()
            .UseKestrel(options =>
            {
                options.UseSystemd();
            })
            .UseStartup<Startup>()
            .Build();
host.Run();

There is a follow-up issue to make it easier to configure Kestrel endpoints from config given the new Listen* APIs. See aspnet/KestrelHttpServer#1305 for discussion.

@halter73 halter73 added this to the 2.0.0 milestone Jan 11, 2017
@aspnet aspnet locked and limited conversation to collaborators Jan 11, 2017
@danroth27 danroth27 added the 2.0.0 label Aug 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants