/// <summary>
        /// Creates a configuration loader for setting up Kestrel that takes an IConfiguration as input.
        /// This configuration must be scoped to the configuration section for Kestrel.
        /// </summary>
        public KestrelConfigurationLoader Configure(IConfiguration config)
        {
            var loader = new KestrelConfigurationLoader(this, config);

            ConfigurationLoader = loader;
            return(loader);
        }
Beispiel #2
0
        public async Task CanReadAndWriteWithHttpsConnectionMiddlewareWithPemCertificate()
        {
            var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary <string, string>
            {
                ["Certificates:Default:Path"]     = Path.Combine("shared", "TestCertificates", "https-aspnet.crt"),
                ["Certificates:Default:KeyPath"]  = Path.Combine("shared", "TestCertificates", "https-aspnet.key"),
                ["Certificates:Default:Password"] = "******",
            }).Build();

            var options = new KestrelServerOptions();
            var env     = new Mock <IHostEnvironment>();

            env.SetupGet(e => e.ContentRootPath).Returns(Directory.GetCurrentDirectory());

            options.ApplicationServices = new ServiceCollection().AddSingleton(env.Object).AddLogging().BuildServiceProvider();
            var loader = new KestrelConfigurationLoader(options, configuration, reloadOnChange: false);

            loader.Load();
            void ConfigureListenOptions(ListenOptions listenOptions)
            {
                listenOptions.KestrelServerOptions = options;
                listenOptions.UseHttps();
            };

            await using (var server = new TestServer(App, new TestServiceContext(LoggerFactory), ConfigureListenOptions))
            {
                var result = await server.HttpClientSlim.PostAsync($"https://localhost:{server.Port}/",
                                                                   new FormUrlEncodedContent(new[] {
                    new KeyValuePair <string, string>("content", "Hello World?")
                }),
                                                                   validateCertificate : false);

                Assert.Equal("content=Hello+World%3F", result);
            }
        }
        /// <summary>
        /// Creates a configuration loader for setting up Kestrel.
        /// </summary>
        public KestrelConfigurationLoader Configure()
        {
            var loader = new KestrelConfigurationLoader(this, new ConfigurationBuilder().Build());

            ConfigurationLoader = loader;
            return(loader);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a configuration loader for setting up Kestrel that takes an <see cref="IConfiguration"/> as input.
        /// This configuration must be scoped to the configuration section for Kestrel.
        /// </summary>
        /// <param name="config">The configuration section for Kestrel.</param>
        /// <param name="reloadOnChange">
        /// If <see langword="true" />, Kestrel will dynamically update endpoint bindings when configuration changes.
        /// This will only reload endpoints defined in the "Endpoints" section of your <paramref name="config"/>. Endpoints defined in code will not be reloaded.
        /// </param>
        /// <returns>A <see cref="KestrelConfigurationLoader"/> for further endpoint configuration.</returns>
        public KestrelConfigurationLoader Configure(IConfiguration config, bool reloadOnChange)
        {
            var loader = new KestrelConfigurationLoader(this, config, reloadOnChange);

            ConfigurationLoader = loader;
            return(loader);
        }