public HttpServerImplementation(IConfiguration configuration) { this.Configuration = configuration; this.Param = GlobalObjectExchange.Withdraw(this.Configuration["coreutil_param_token"]); this.CancelToken = (CancellationToken)GlobalObjectExchange.Withdraw(this.Configuration["coreutil_cancel_token"]); this.builder_config = this.Configuration["coreutil_ServerBuilderConfig"].JsonToObject <HttpServerBuilderConfig>(); this.startup_config = new HttpServerStartupConfig(); }
public HttpServer(HttpServerBuilderConfig cfg, object param) { this.config = cfg; IO.MakeDirIfNotExists(config.ContentsRoot); string param_token = GlobalObjectExchange.Deposit(param); string cancel_token = GlobalObjectExchange.Deposit(cancel.Token); try { var dict = new Dictionary <string, string> { { "coreutil_ServerBuilderConfig", this.config.ObjectToJson() }, { "coreutil_param_token", param_token }, { "coreutil_cancel_token", cancel_token }, }; IConfiguration iconf = new ConfigurationBuilder() .AddInMemoryCollection(dict) .Build(); var h = new WebHostBuilder() .UseKestrel(opt => { if (config.LocalHostOnly) { foreach (int port in config.HttpPortsList) { opt.ListenLocalhost(port); } foreach (int port in config.HttpsPortsList) { opt.ListenLocalhost(port, lo => { lo.UseHttps(so => { so.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; }); }); } } else if (config.IPv4Only) { foreach (int port in config.HttpPortsList) { opt.Listen(IPAddress.Any, port); } foreach (int port in config.HttpsPortsList) { opt.Listen(IPAddress.Any, port, lo => { lo.UseHttps(so => { so.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; }); }); } } else { foreach (int port in config.HttpPortsList) { opt.ListenAnyIP(port); } foreach (int port in config.HttpsPortsList) { opt.ListenAnyIP(port, lo => { lo.UseHttps(so => { so.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; }); }); } } }) .UseWebRoot(config.ContentsRoot) .UseContentRoot(config.ContentsRoot) .ConfigureAppConfiguration((hostingContext, config) => { }) .ConfigureLogging((hostingContext, logging) => { if (config.DebugToConsole) { logging.AddConsole(); logging.AddDebug(); } }) .UseConfiguration(iconf) .UseStartup <THttpServerStartup>() .Build(); hosttask = h.RunAsync(cancel.Token); } catch { GlobalObjectExchange.TryWithdraw(param_token); GlobalObjectExchange.TryWithdraw(cancel_token); throw; } }