public void ConfigureThrowsInvalidOperationExceptionIfApplicationServicesDoesntHaveRequiredServices() { var options = new KestrelServerOptions { ApplicationServices = new ServiceCollection().BuildServiceProvider() }; Assert.Throws <InvalidOperationException>(() => options.Configure()); }
public void CanCallListenAfterConfigure() { var options = new KestrelServerOptions(); options.Configure(); // This is a regression test to verify the Listen* methods don't throw a NullReferenceException if called after Configure(). // https://github.com/dotnet/aspnetcore/issues/21423 options.ListenLocalhost(5000); }
public static IOptions <KestrelServerOptions> GetKestrelServerOptions(IServiceProvider serviceProvider) { var kestrelServerOptions = new KestrelServerOptions { ApplicationServices = serviceProvider }; kestrelServerOptions.Configure().AnyIPEndpoint(8080); var optionFactory = Options.Create <KestrelServerOptions>(kestrelServerOptions); return(optionFactory); }
private static void AddKestrelServerOptions(WebHostBuilderContext builderContext, KestrelServerOptions options) { var tcpListenPort = 9900; options.ListenAnyIP(tcpListenPort, builder => { builder.UseConnectionHandler <MyEchoConnectionHandler>(); }); // Configure Kestrel from appsettings.json. var kestrelConfig = builderContext.Configuration.GetSection("Kestrel"); options.Configure(kestrelConfig); }
private static void ConfigureKestrel(WebHostBuilderContext builderContext, KestrelServerOptions options) { options.AddServerHeader = false; options.Limits.MaxRequestLineSize = 1024; options.Limits.MaxRequestBodySize = 1 << 20; options.Limits.MaxRequestHeadersTotalSize = 8192; var kestrelSection = builderContext.Configuration.GetSection("Kestrel"); options.Configure(kestrelSection); if (kestrelSection.Get <KestrelServerOptions>() is { } kestrelOptions) { options.Limits.MaxConcurrentConnections = kestrelOptions.Limits.MaxConcurrentConnections; }
private static void ConfigureKestrel(WebHostBuilderContext builderContext, KestrelServerOptions options) { options.AddServerHeader = false; options.Limits.MaxRequestBodySize = 0; options.Limits.MaxRequestHeadersTotalSize = 4096; // To match all single-chunk files options.Limits.MaxResponseBufferSize = 257 << 10; var kestrelSection = builderContext.Configuration.GetSection("Kestrel"); options.Configure(kestrelSection); if (kestrelSection.Get <KestrelServerOptions>() is { } kestrelOptions) { options.Limits.MaxConcurrentConnections = kestrelOptions.Limits.MaxConcurrentConnections; }
public void CanCallListenAfterConfigure() { var options = new KestrelServerOptions(); // Ensure configure doesn't throw because of missing services. var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(Mock.Of <IHostEnvironment>()); serviceCollection.AddSingleton(Mock.Of <ILogger <KestrelServer> >()); serviceCollection.AddSingleton(Mock.Of <ILogger <HttpsConnectionMiddleware> >()); options.ApplicationServices = serviceCollection.BuildServiceProvider(); options.Configure(); // This is a regression test to verify the Listen* methods don't throw a NullReferenceException if called after Configure(). // https://github.com/dotnet/aspnetcore/issues/21423 options.ListenLocalhost(5000); }
private static void ConfigureKestrel(WebHostBuilderContext builderContext, KestrelServerOptions options) { var kestrelConfiguration = builderContext.Configuration.GetSection("Kestrel"); // If the environment variable ASPNETCORE_URL is available, override the config urls var environmentUrls = Environment.GetEnvironmentVariable("ASPNETCORE_URLS")?.Split(';'); if (environmentUrls != null && environmentUrls.Length > 0) { Console.WriteLine("Using environment variable ASPNETCORE_URLS urls instead of appsettings Kestrel config"); var httpEndpoint = environmentUrls.FirstOrDefault(url => url.Contains("http://")); if (httpEndpoint != null) { kestrelConfiguration["EndPoints:Http:Url"] = httpEndpoint; } var httpsEndpoint = environmentUrls.FirstOrDefault(url => url.Contains("https://")); if (httpsEndpoint != null) { kestrelConfiguration["EndPoints:Http:Url"] = httpsEndpoint; } } options.Configure(kestrelConfiguration); }
public void ConfigureThrowsInvalidOperationExceptionIfApplicationServicesIsNotSet() { var options = new KestrelServerOptions(); Assert.Throws <InvalidOperationException>(() => options.Configure()); }