[Kestrel] Move to GenericHost (#24279)
* [Kestrel] Move to GenericHost * Change TransportSelector * Add an empty app for TestServer * Add an empty app for TestServer * Set app * Stop host * Stop the TestSserver * Stop more hosts! * Stop host in dispose * implement IAsyncDisposable for TestServer * configure await * catch OperationCanceledException * Apply suggestions from code review Co-authored-by: Brennan <brecon@microsoft.com>
This commit is contained in:
parent
25948ab962
commit
b2c7d514c9
|
|
@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Connections;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
||||
{
|
||||
|
|
@ -33,22 +34,26 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
|
|||
private static readonly string _plaintextPipelinedExpectedResponse =
|
||||
string.Concat(Enumerable.Repeat(_plaintextExpectedResponse, RequestParsingData.Pipelining));
|
||||
|
||||
private IWebHost _host;
|
||||
private IHost _host;
|
||||
private InMemoryConnection _connection;
|
||||
|
||||
[GlobalSetup(Target = nameof(Plaintext) + "," + nameof(PlaintextPipelined))]
|
||||
public void GlobalSetupPlaintext()
|
||||
{
|
||||
var transportFactory = new InMemoryTransportFactory(connectionsPerEndPoint: 1);
|
||||
|
||||
_host = new WebHostBuilder()
|
||||
// Prevent VS from attaching to hosting startup which could impact results
|
||||
.UseSetting("preventHostingStartup", "true")
|
||||
.UseKestrel()
|
||||
// Bind to a single non-HTTPS endpoint
|
||||
.UseUrls("http://127.0.0.1:5000")
|
||||
|
||||
_host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
// Prevent VS from attaching to hosting startup which could impact results
|
||||
.UseSetting("preventHostingStartup", "true")
|
||||
.UseKestrel()
|
||||
// Bind to a single non-HTTPS endpoint
|
||||
.UseUrls("http://127.0.0.1:5000")
|
||||
.Configure(app => app.UseMiddleware<PlaintextMiddleware>());
|
||||
})
|
||||
.ConfigureServices(services => services.AddSingleton<IConnectionListenerFactory>(transportFactory))
|
||||
.Configure(app => app.UseMiddleware<PlaintextMiddleware>())
|
||||
.Build();
|
||||
|
||||
_host.Start();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Authentication;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Http2SampleApp
|
||||
|
|
@ -15,54 +15,58 @@ namespace Http2SampleApp
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
// Http/1.1 endpoint for comparison
|
||||
options.ListenAnyIP(basePort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1;
|
||||
});
|
||||
|
||||
// TLS Http/1.1 or HTTP/2 endpoint negotiated via ALPN
|
||||
options.ListenAnyIP(basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.Use((context, next) =>
|
||||
{
|
||||
// https://tools.ietf.org/html/rfc7540#appendix-A
|
||||
// Allows filtering TLS handshakes on a per connection basis
|
||||
|
||||
var tlsFeature = context.Features.Get<ITlsHandshakeFeature>();
|
||||
|
||||
if (tlsFeature.CipherAlgorithm == CipherAlgorithmType.Null)
|
||||
{
|
||||
throw new NotSupportedException("Prohibited cipher: " + tlsFeature.CipherAlgorithm);
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
});
|
||||
|
||||
// Prior knowledge, no TLS handshake. WARNING: Not supported by browsers
|
||||
// but useful for the h2spec tests
|
||||
options.ListenAnyIP(basePort + 5, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
});
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
// Set logging to the MAX.
|
||||
factory.SetMinimumLevel(LogLevel.Trace);
|
||||
factory.AddConsole();
|
||||
})
|
||||
.UseKestrel()
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
// Http/1.1 endpoint for comparison
|
||||
options.ListenAnyIP(basePort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1;
|
||||
});
|
||||
|
||||
// TLS Http/1.1 or HTTP/2 endpoint negotiated via ALPN
|
||||
options.ListenAnyIP(basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.Use((context, next) =>
|
||||
{
|
||||
// https://tools.ietf.org/html/rfc7540#appendix-A
|
||||
// Allows filtering TLS handshakes on a per connection basis
|
||||
|
||||
var tlsFeature = context.Features.Get<ITlsHandshakeFeature>();
|
||||
|
||||
if (tlsFeature.CipherAlgorithm == CipherAlgorithmType.Null)
|
||||
{
|
||||
throw new NotSupportedException("Prohibited cipher: " + tlsFeature.CipherAlgorithm);
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
});
|
||||
|
||||
// Prior knowledge, no TLS handshake. WARNING: Not supported by browsers
|
||||
// but useful for the h2spec tests
|
||||
options.ListenAnyIP(basePort + 5, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
});
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
});
|
||||
|
||||
hostBuilder.Build().Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace LargeResponseApp
|
||||
{
|
||||
|
|
@ -38,13 +39,17 @@ namespace LargeResponseApp
|
|||
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 5001);
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 5001);
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
return host.RunAsync();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace PlaintextApp
|
||||
{
|
||||
|
|
@ -34,13 +35,17 @@ namespace PlaintextApp
|
|||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 5001);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 5001);
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
await host.RunAsync();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace QuicSampleApp
|
||||
|
|
@ -22,60 +23,64 @@ namespace QuicSampleApp
|
|||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
factory.SetMinimumLevel(LogLevel.Debug);
|
||||
factory.AddConsole();
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseQuic(options =>
|
||||
{
|
||||
options.Certificate = null;
|
||||
options.Alpn = "QuicTest";
|
||||
options.IdleTimeout = TimeSpan.FromHours(1);
|
||||
})
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
var basePort = 5555;
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseQuic(options =>
|
||||
{
|
||||
options.Certificate = null;
|
||||
options.Alpn = "QuicTest";
|
||||
options.IdleTimeout = TimeSpan.FromHours(1);
|
||||
})
|
||||
.ConfigureKestrel((context, options) =>
|
||||
{
|
||||
var basePort = 5555;
|
||||
|
||||
options.Listen(IPAddress.Any, basePort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http3;
|
||||
options.Listen(IPAddress.Any, basePort, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http3;
|
||||
|
||||
async Task EchoServer(MultiplexedConnectionContext connection)
|
||||
{
|
||||
// For graceful shutdown
|
||||
async Task EchoServer(MultiplexedConnectionContext connection)
|
||||
{
|
||||
// For graceful shutdown
|
||||
|
||||
while (true)
|
||||
{
|
||||
var stream = await connection.AcceptAsync();
|
||||
while (true)
|
||||
{
|
||||
var result = await stream.Transport.Input.ReadAsync();
|
||||
while (true)
|
||||
{
|
||||
var stream = await connection.AcceptAsync();
|
||||
while (true)
|
||||
{
|
||||
var result = await stream.Transport.Input.ReadAsync();
|
||||
|
||||
if (result.IsCompleted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (result.IsCompleted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await stream.Transport.Output.WriteAsync(result.Buffer.ToArray());
|
||||
await stream.Transport.Output.WriteAsync(result.Buffer.ToArray());
|
||||
|
||||
stream.Transport.Input.AdvanceTo(result.Buffer.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.Transport.Input.AdvanceTo(result.Buffer.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
((IMultiplexedConnectionBuilder)listenOptions).Use(next =>
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
return EchoServer(context);
|
||||
};
|
||||
});
|
||||
});
|
||||
})
|
||||
.UseStartup<Startup>();
|
||||
((IMultiplexedConnectionBuilder)listenOptions).Use(next =>
|
||||
{
|
||||
return context =>
|
||||
{
|
||||
return EchoServer(context);
|
||||
};
|
||||
});
|
||||
});
|
||||
})
|
||||
.UseStartup<Startup>();
|
||||
})
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
factory.SetMinimumLevel(LogLevel.Debug);
|
||||
factory.AddConsole();
|
||||
});
|
||||
|
||||
hostBuilder.Build().Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,102 @@ namespace SampleApp
|
|||
Console.WriteLine("Unobserved exception: {0}", e.Exception);
|
||||
};
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel((context, options) =>
|
||||
{
|
||||
if (context.HostingEnvironment.IsDevelopment())
|
||||
{
|
||||
ShowConfig(context.Configuration);
|
||||
}
|
||||
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
options.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.SslProtocols = SslProtocols.Tls12;
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort, listenOptions =>
|
||||
{
|
||||
// Uncomment the following to enable Nagle's algorithm for this endpoint.
|
||||
//listenOptions.NoDelay = false;
|
||||
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.ListenLocalhost(basePort + 2, listenOptions =>
|
||||
{
|
||||
// Use default dev cert
|
||||
listenOptions.UseHttps();
|
||||
});
|
||||
|
||||
options.ListenAnyIP(basePort + 3);
|
||||
|
||||
options.ListenAnyIP(basePort + 4, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(StoreName.My, "localhost", allowInvalid: true);
|
||||
});
|
||||
|
||||
options.ListenAnyIP(basePort + 5, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(httpsOptions =>
|
||||
{
|
||||
var localhostCert = CertificateLoader.LoadFromStoreCert("localhost", "My", StoreLocation.CurrentUser, allowInvalid: true);
|
||||
httpsOptions.ServerCertificateSelector = (features, name) =>
|
||||
{
|
||||
// Here you would check the name, select an appropriate cert, and provide a fallback or fail for null names.
|
||||
return localhostCert;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
options
|
||||
.Configure()
|
||||
.Endpoint(IPAddress.Loopback, basePort + 6)
|
||||
.LocalhostEndpoint(basePort + 7)
|
||||
.Load();
|
||||
|
||||
// reloadOnChange: true is the default
|
||||
options
|
||||
.Configure(context.Configuration.GetSection("Kestrel"), reloadOnChange: true)
|
||||
.Endpoint("NamedEndpoint", opt =>
|
||||
{
|
||||
|
||||
})
|
||||
.Endpoint("NamedHttpsEndpoint", opt =>
|
||||
{
|
||||
opt.HttpsOptions.SslProtocols = SslProtocols.Tls12;
|
||||
});
|
||||
|
||||
options.UseSystemd();
|
||||
|
||||
// The following section should be used to demo sockets
|
||||
//options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
|
||||
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
|
||||
{
|
||||
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
|
||||
#pragma warning disable CS0618
|
||||
webHostBuilder.UseLibuv(options =>
|
||||
{
|
||||
// Uncomment the following line to change the default number of libuv threads for all endpoints.
|
||||
// options.ThreadCount = 4;
|
||||
});
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
})
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
factory.SetMinimumLevel(LogLevel.Debug);
|
||||
|
|
@ -73,98 +168,7 @@ namespace SampleApp
|
|||
var env = hostingContext.HostingEnvironment;
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
|
||||
})
|
||||
.UseKestrel((context, options) =>
|
||||
{
|
||||
if (context.HostingEnvironment.IsDevelopment())
|
||||
{
|
||||
ShowConfig(context.Configuration);
|
||||
}
|
||||
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
options.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.SslProtocols = SslProtocols.Tls12;
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort, listenOptions =>
|
||||
{
|
||||
// Uncomment the following to enable Nagle's algorithm for this endpoint.
|
||||
//listenOptions.NoDelay = false;
|
||||
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.ListenLocalhost(basePort + 2, listenOptions =>
|
||||
{
|
||||
// Use default dev cert
|
||||
listenOptions.UseHttps();
|
||||
});
|
||||
|
||||
options.ListenAnyIP(basePort + 3);
|
||||
|
||||
options.ListenAnyIP(basePort + 4, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(StoreName.My, "localhost", allowInvalid: true);
|
||||
});
|
||||
|
||||
options.ListenAnyIP(basePort + 5, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(httpsOptions =>
|
||||
{
|
||||
var localhostCert = CertificateLoader.LoadFromStoreCert("localhost", "My", StoreLocation.CurrentUser, allowInvalid: true);
|
||||
httpsOptions.ServerCertificateSelector = (features, name) =>
|
||||
{
|
||||
// Here you would check the name, select an appropriate cert, and provide a fallback or fail for null names.
|
||||
return localhostCert;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
options
|
||||
.Configure()
|
||||
.Endpoint(IPAddress.Loopback, basePort + 6)
|
||||
.LocalhostEndpoint(basePort + 7)
|
||||
.Load();
|
||||
|
||||
// reloadOnChange: true is the default
|
||||
options
|
||||
.Configure(context.Configuration.GetSection("Kestrel"), reloadOnChange: true)
|
||||
.Endpoint("NamedEndpoint", opt =>
|
||||
{
|
||||
|
||||
})
|
||||
.Endpoint("NamedHttpsEndpoint", opt =>
|
||||
{
|
||||
opt.HttpsOptions.SslProtocols = SslProtocols.Tls12;
|
||||
});
|
||||
|
||||
options.UseSystemd();
|
||||
|
||||
// The following section should be used to demo sockets
|
||||
//options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
|
||||
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
|
||||
{
|
||||
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
|
||||
#pragma warning disable CS0618
|
||||
hostBuilder.UseLibuv(options =>
|
||||
{
|
||||
// Uncomment the following line to change the default number of libuv threads for all endpoints.
|
||||
// options.ThreadCount = 4;
|
||||
});
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
});
|
||||
|
||||
return hostBuilder.Build().RunAsync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SystemdTestApp
|
||||
|
|
@ -41,48 +42,52 @@ namespace SystemdTestApp
|
|||
Console.WriteLine("Unobserved exception: {0}", e.Exception);
|
||||
};
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel((context, options) =>
|
||||
{
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort, listenOptions =>
|
||||
{
|
||||
// Uncomment the following to enable Nagle's algorithm for this endpoint.
|
||||
//listenOptions.NoDelay = false;
|
||||
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.UseSystemd();
|
||||
|
||||
// The following section should be used to demo sockets
|
||||
//options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
|
||||
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
|
||||
{
|
||||
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
|
||||
#pragma warning disable CS0618
|
||||
webHostBuilder.UseLibuv(options =>
|
||||
{
|
||||
// Uncomment the following line to change the default number of libuv threads for all endpoints.
|
||||
// options.ThreadCount = 4;
|
||||
});
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
})
|
||||
.ConfigureLogging((_, factory) =>
|
||||
{
|
||||
factory.AddConsole();
|
||||
})
|
||||
.UseKestrel((context, options) =>
|
||||
{
|
||||
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort, listenOptions =>
|
||||
{
|
||||
// Uncomment the following to enable Nagle's algorithm for this endpoint.
|
||||
//listenOptions.NoDelay = false;
|
||||
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.Listen(IPAddress.Loopback, basePort + 1, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
listenOptions.UseConnectionLogging();
|
||||
});
|
||||
|
||||
options.UseSystemd();
|
||||
|
||||
// The following section should be used to demo sockets
|
||||
//options.ListenUnixSocket("/tmp/kestrel-test.sock");
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>();
|
||||
|
||||
if (string.Equals(Process.GetCurrentProcess().Id.ToString(), Environment.GetEnvironmentVariable("LISTEN_PID")))
|
||||
{
|
||||
// Use libuv if activated by systemd, since that's currently the only transport that supports being passed a socket handle.
|
||||
#pragma warning disable CS0618
|
||||
hostBuilder.UseLibuv(options =>
|
||||
{
|
||||
// Uncomment the following line to change the default number of libuv threads for all endpoints.
|
||||
// options.ThreadCount = 4;
|
||||
});
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
});
|
||||
|
||||
return hostBuilder.Build().RunAsync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
/// <summary>
|
||||
/// Summary description for TestServer
|
||||
/// </summary>
|
||||
internal class TestServer : IDisposable, IStartup
|
||||
internal class TestServer : IAsyncDisposable, IStartup
|
||||
{
|
||||
private IWebHost _host;
|
||||
private IHost _host;
|
||||
private ListenOptions _listenOptions;
|
||||
private readonly RequestDelegate _app;
|
||||
|
||||
|
|
@ -70,32 +70,37 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
_app = app;
|
||||
Context = context;
|
||||
|
||||
_host = TransportSelector.GetWebHostBuilder(context.MemoryPoolFactory, context.ServerOptions.Limits.MaxRequestBufferSize)
|
||||
.UseKestrel(options =>
|
||||
_host = TransportSelector.GetHostBuilder(context.MemoryPoolFactory, context.ServerOptions.Limits.MaxRequestBufferSize)
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
configureKestrel(options);
|
||||
_listenOptions = options.ListenOptions.First();
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IStartup>(this);
|
||||
services.AddSingleton(context.LoggerFactory);
|
||||
services.AddSingleton<IServer>(sp =>
|
||||
{
|
||||
// Manually configure options on the TestServiceContext.
|
||||
// We're doing this so we can use the same instance that was passed in
|
||||
var configureOptions = sp.GetServices<IConfigureOptions<KestrelServerOptions>>();
|
||||
foreach (var c in configureOptions)
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
c.Configure(context.ServerOptions);
|
||||
}
|
||||
configureKestrel(options);
|
||||
_listenOptions = options.ListenOptions.First();
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IStartup>(this);
|
||||
services.AddSingleton(context.LoggerFactory);
|
||||
services.AddSingleton<IServer>(sp =>
|
||||
{
|
||||
// Manually configure options on the TestServiceContext.
|
||||
// We're doing this so we can use the same instance that was passed in
|
||||
var configureOptions = sp.GetServices<IConfigureOptions<KestrelServerOptions>>();
|
||||
foreach (var c in configureOptions)
|
||||
{
|
||||
c.Configure(context.ServerOptions);
|
||||
}
|
||||
|
||||
return new KestrelServer(new List<IConnectionListenerFactory>() { sp.GetRequiredService<IConnectionListenerFactory>() }, context);
|
||||
});
|
||||
configureServices(services);
|
||||
return new KestrelServer(new List<IConnectionListenerFactory>() { sp.GetRequiredService<IConnectionListenerFactory>() }, context);
|
||||
});
|
||||
configureServices(services);
|
||||
})
|
||||
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName)
|
||||
.UseSetting(WebHostDefaults.ShutdownTimeoutKey, TestConstants.DefaultTimeout.TotalSeconds.ToString())
|
||||
.Configure(app => { app.Run(_app); });
|
||||
})
|
||||
.UseSetting(WebHostDefaults.ApplicationKey, typeof(TestServer).GetTypeInfo().Assembly.FullName)
|
||||
.UseSetting(WebHostDefaults.ShutdownTimeoutKey, TestConstants.DefaultTimeout.TotalSeconds.ToString())
|
||||
.Build();
|
||||
|
||||
_host.Start();
|
||||
|
|
@ -130,9 +135,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
return _host.StopAsync(token);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_host.Dispose();
|
||||
await _host.StopAsync().ConfigureAwait(false);
|
||||
// The concrete Host implements IAsyncDisposable
|
||||
await ((IAsyncDisposable)_host).DisposeAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,11 @@ using Microsoft.AspNetCore.Testing;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
using Xunit.Sdk;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||
{
|
||||
|
|
@ -182,17 +185,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task RegisterAddresses_Success(string addressInput, string[] testUrls, int testPort = 0)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(serverOptions =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
serverOptions.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(serverOptions =>
|
||||
{
|
||||
serverOptions.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.ServerCertificate = TestResources.GetTestCertificate();
|
||||
});
|
||||
})
|
||||
.UseUrls(addressInput)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseUrls(addressInput)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -214,6 +221,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
Assert.Equal(uri.ToString(), response);
|
||||
}
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -226,25 +235,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Fact]
|
||||
public async Task RegisterHttpAddress_UpgradedToHttpsByConfigureEndpointDefaults()
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(serverOptions =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
serverOptions.ConfigureEndpointDefaults(listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(serverOptions =>
|
||||
{
|
||||
serverOptions.ConfigureEndpointDefaults(listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
})
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app =>
|
||||
{
|
||||
var serverAddresses = app.ServerFeatures.Get<IServerAddressesFeature>();
|
||||
app.Run(context =>
|
||||
{
|
||||
Assert.Single(serverAddresses.Addresses);
|
||||
return context.Response.WriteAsync(serverAddresses.Addresses.First());
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app =>
|
||||
{
|
||||
var serverAddresses = app.ServerFeatures.Get<IServerAddressesFeature>();
|
||||
app.Run(context =>
|
||||
{
|
||||
Assert.Single(serverAddresses.Addresses);
|
||||
return context.Response.WriteAsync(serverAddresses.Addresses.First());
|
||||
});
|
||||
});
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -254,6 +267,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var response = await HttpClientSlim.GetStringAsync(expectedUrl, validateCertificate: false);
|
||||
|
||||
Assert.Equal(expectedUrl, response);
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -293,19 +308,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task RegisterIPEndPoint_Success(IPEndPoint endPoint, string testUrl, int testPort = 0)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(endPoint, listenOptions =>
|
||||
{
|
||||
if (testUrl.StartsWith("https"))
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
}
|
||||
});
|
||||
options.Listen(endPoint, listenOptions =>
|
||||
{
|
||||
if (testUrl.StartsWith("https"))
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
}
|
||||
});
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -353,13 +372,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task ListenAnyIP_Success(string[] testUrls, int testPort = 0)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.ListenAnyIP(testPort);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.ListenAnyIP(testPort);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -396,13 +419,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task ListenLocalhost_Success(string[] testUrls, int testPort = 0)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.ListenLocalhost(testPort);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.ListenLocalhost(testPort);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -478,16 +505,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task RegisterDefaultServerAddresses_Success(IEnumerable<string> addresses, bool mockHttps = false)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
if (mockHttps)
|
||||
{
|
||||
options.DefaultCertificate = TestResources.GetTestCertificate();
|
||||
}
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
if (mockHttps)
|
||||
{
|
||||
options.DefaultCertificate = TestResources.GetTestCertificate();
|
||||
}
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -514,7 +545,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowsWhenBindingToIPv4AddressInUse()
|
||||
public async Task ThrowsWhenBindingToIPv4AddressInUse()
|
||||
{
|
||||
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
|
|
@ -522,22 +553,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
socket.Listen(0);
|
||||
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://127.0.0.1:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://127.0.0.1:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
});
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
var exception = Assert.Throws<IOException>(() => host.Start());
|
||||
Assert.Equal(CoreStrings.FormatEndpointAlreadyInUse($"http://127.0.0.1:{port}"), exception.Message);
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[IPv6SupportedCondition]
|
||||
public void ThrowsWhenBindingToIPv6AddressInUse()
|
||||
public async Task ThrowsWhenBindingToIPv6AddressInUse()
|
||||
{
|
||||
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(IOException));
|
||||
|
||||
|
|
@ -547,16 +584,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
socket.Listen(0);
|
||||
var port = ((IPEndPoint)socket.LocalEndPoint).Port;
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://[::1]:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://[::1]:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
var exception = Assert.Throws<IOException>(() => host.Start());
|
||||
Assert.Equal(CoreStrings.FormatEndpointAlreadyInUse($"http://[::1]:{port}"), exception.Message);
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -565,18 +608,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
public async Task OverrideDirectConfigurationWithIServerAddressesFeature_Succeeds()
|
||||
{
|
||||
var useUrlsAddress = $"http://127.0.0.1:0";
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
})
|
||||
.UseUrls(useUrlsAddress)
|
||||
.PreferHostingUrls(true)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.UseUrls(useUrlsAddress)
|
||||
.PreferHostingUrls(true)
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -586,7 +633,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
// If this isn't working properly, we'll get the HTTPS endpoint defined in UseKestrel
|
||||
// instead of the HTTP endpoint defined in UseUrls.
|
||||
var serverAddresses = host.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
|
||||
var serverAddresses = host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
|
||||
Assert.Equal(1, serverAddresses.Count);
|
||||
var useUrlsAddressWithPort = $"http://127.0.0.1:{port}";
|
||||
Assert.Equal(serverAddresses.First(), useUrlsAddressWithPort);
|
||||
|
|
@ -606,18 +653,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
{
|
||||
var useUrlsAddress = $"http://127.0.0.1:0";
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.TestCertificatePath, "testPassword");
|
||||
});
|
||||
})
|
||||
.UseUrls($"http://127.0.0.1:0")
|
||||
.PreferHostingUrls(false)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.UseUrls($"http://127.0.0.1:0")
|
||||
.PreferHostingUrls(false)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -627,7 +678,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
// If this isn't working properly, we'll get the HTTP endpoint defined in UseUrls
|
||||
// instead of the HTTPS endpoint defined in UseKestrel.
|
||||
var serverAddresses = host.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
|
||||
var serverAddresses = host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
|
||||
Assert.Equal(1, serverAddresses.Count);
|
||||
var endPointAddress = $"https://127.0.0.1:{port}";
|
||||
Assert.Equal(serverAddresses.First(), endPointAddress);
|
||||
|
|
@ -644,17 +695,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Fact]
|
||||
public async Task DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddressesEmpty()
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
})
|
||||
.PreferHostingUrls(true)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.PreferHostingUrls(true)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -663,7 +718,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var port = host.GetPort();
|
||||
|
||||
// If this isn't working properly, we'll not get the HTTPS endpoint defined in UseKestrel.
|
||||
var serverAddresses = host.ServerFeatures.Get<IServerAddressesFeature>().Addresses;
|
||||
var serverAddresses = host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
|
||||
Assert.Equal(1, serverAddresses.Count);
|
||||
var endPointAddress = $"https://127.0.0.1:{port}";
|
||||
Assert.Equal(serverAddresses.First(), endPointAddress);
|
||||
|
|
@ -688,38 +743,50 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowsWhenBindingLocalhostToDynamicPort()
|
||||
public async Task ThrowsWhenBindingLocalhostToDynamicPort()
|
||||
{
|
||||
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException));
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel()
|
||||
.UseUrls("http://localhost:0")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://localhost:0")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() => host.Start());
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("ftp://localhost")]
|
||||
[InlineData("ssh://localhost")]
|
||||
public void ThrowsForUnsupportedAddressFromHosting(string address)
|
||||
public async Task ThrowsForUnsupportedAddressFromHosting(string address)
|
||||
{
|
||||
TestApplicationErrorLogger.IgnoredExceptions.Add(typeof(InvalidOperationException));
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel()
|
||||
.UseUrls(address)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls(address)
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() => host.Start());
|
||||
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -729,13 +796,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var port = GetNextPort();
|
||||
var endPointAddress = $"http://127.0.0.1:{port}/";
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -746,12 +817,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await host.StopAsync();
|
||||
}
|
||||
|
||||
hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
});
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -771,14 +846,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var ipv4endPointAddress = $"http://127.0.0.1:{port}/";
|
||||
var ipv6endPointAddress = $"http://[::1]:{port}/";
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
options.Listen(IPAddress.IPv6Loopback, port);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
options.Listen(IPAddress.IPv6Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -790,13 +869,17 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await host.StopAsync();
|
||||
}
|
||||
|
||||
hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
options.Listen(IPAddress.IPv6Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
options.Listen(IPAddress.IPv6Loopback, port);
|
||||
})
|
||||
.Configure(ConfigureEchoAddress);
|
||||
});
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -816,20 +899,24 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
public async Task EndpointDefaultsConfig_CanSetProtocolForUrlsConfig(string input, HttpProtocols expected)
|
||||
{
|
||||
KestrelServerOptions capturedOptions = null;
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("EndpointDefaults:Protocols", input),
|
||||
}).Build();
|
||||
options.Configure(config);
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddInMemoryCollection(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("EndpointDefaults:Protocols", input),
|
||||
}).Build();
|
||||
options.Configure(config);
|
||||
|
||||
capturedOptions = options;
|
||||
capturedOptions = options;
|
||||
})
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -875,11 +962,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
continue;
|
||||
}
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://localhost:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://localhost:{port}")
|
||||
.Configure(ConfigureEchoAddress);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var serviceContext = new TestServiceContext(LoggerFactory);
|
||||
|
||||
using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||
await using (var server = new TestServer(TestApp.EchoApp, serviceContext, listenOptions))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -41,7 +41,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
});
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10)]
|
||||
public async Task TlsAlpnHandshakeSelectsHttp2From1and2()
|
||||
{
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
var tlsFeature = context.Features.Get<ITlsApplicationProtocolFeature>();
|
||||
Assert.NotNull(tlsFeature);
|
||||
|
|
@ -103,8 +103,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
{
|
||||
var result = await Client.GetStringAsync($"https://localhost:{server.Port}/");
|
||||
Assert.Equal("hello world HTTP/2", result);
|
||||
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +111,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win10)]
|
||||
public async Task TlsAlpnHandshakeSelectsHttp2()
|
||||
{
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
var tlsFeature = context.Features.Get<ITlsApplicationProtocolFeature>();
|
||||
Assert.NotNull(tlsFeature);
|
||||
|
|
@ -133,7 +131,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
{
|
||||
var result = await Client.GetStringAsync($"https://localhost:{server.Port}/");
|
||||
Assert.Equal("hello world HTTP/2", result);
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
|
||||
testContext.InitializeHeartbeat();
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
requestStarted.SetResult();
|
||||
await requestUnblocked.Task.DefaultTimeout();
|
||||
|
|
@ -115,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
TestApplicationErrorLogger.ThrowOnUngracefulShutdown = false;
|
||||
|
||||
// Abortive shutdown leaves one request hanging
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
requestStarted.SetResult();
|
||||
await requestUnblocked.Task.DefaultTimeout();
|
||||
|
|
@ -145,7 +145,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.Http2
|
|||
|
||||
await closingMessageTask;
|
||||
cts.Cancel();
|
||||
await stopServerTask;
|
||||
try
|
||||
{
|
||||
await stopServerTask;
|
||||
}
|
||||
// Remove when https://github.com/dotnet/runtime/issues/40290 is fixed
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Message.Contains("is closing."));
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
{
|
||||
_canListenToOpenTcpSocketHandleSocket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
|
||||
using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(LoggerFactory),
|
||||
await using (var server = new TestServer(_ => Task.CompletedTask, new TestServiceContext(LoggerFactory),
|
||||
new ListenOptions((ulong)_canListenToOpenTcpSocketHandleSocket.Handle)))
|
||||
{
|
||||
using (var connection = new TestConnection(((IPEndPoint)_canListenToOpenTcpSocketHandleSocket.LocalEndPoint).Port))
|
||||
|
|
@ -42,7 +42,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
"",
|
||||
"");
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||
|
|
@ -124,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var memoryPoolFactory = new DiagnosticMemoryPoolFactory(allowLateReturn: true);
|
||||
|
||||
using (var host = await StartWebHost(maxRequestBufferSize, data, connectionAdapter, startReadingRequestBody, clientFinishedSendingRequestBody, memoryPoolFactory.Create))
|
||||
using (var host = await StartHost(maxRequestBufferSize, data, connectionAdapter, startReadingRequestBody, clientFinishedSendingRequestBody, memoryPoolFactory.Create))
|
||||
{
|
||||
var port = host.GetPort();
|
||||
using (var socket = CreateSocket(port))
|
||||
|
|
@ -217,7 +218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var memoryPoolFactory = new DiagnosticMemoryPoolFactory(allowLateReturn: true);
|
||||
|
||||
using (var host = await StartWebHost(16 * 1024, data, false, startReadingRequestBody, clientFinishedSendingRequestBody, memoryPoolFactory.Create))
|
||||
using (var host = await StartHost(16 * 1024, data, false, startReadingRequestBody, clientFinishedSendingRequestBody, memoryPoolFactory.Create))
|
||||
{
|
||||
var port = host.GetPort();
|
||||
using (var socket = CreateSocket(port))
|
||||
|
|
@ -271,7 +272,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
// Dispose host prior to closing connection to verify the server doesn't throw during shutdown
|
||||
// if a connection no longer has alloc and read callbacks configured.
|
||||
await host.StopAsync();
|
||||
try
|
||||
{
|
||||
await host.StopAsync();
|
||||
}
|
||||
// Remove when https://github.com/dotnet/runtime/issues/40290 is fixed
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
host.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -281,67 +290,71 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await memoryPoolFactory.WhenAllBlocksReturned(TestConstants.DefaultTimeout);
|
||||
}
|
||||
|
||||
private async Task<IWebHost> StartWebHost(long? maxRequestBufferSize,
|
||||
private async Task<IHost> StartHost(long? maxRequestBufferSize,
|
||||
byte[] expectedBody,
|
||||
bool useConnectionAdapter,
|
||||
TaskCompletionSource startReadingRequestBody,
|
||||
TaskCompletionSource clientFinishedSendingRequestBody,
|
||||
Func<MemoryPool<byte>> memoryPoolFactory = null)
|
||||
{
|
||||
var host = TransportSelector.GetWebHostBuilder(memoryPoolFactory, maxRequestBufferSize)
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var host = TransportSelector.GetHostBuilder(memoryPoolFactory, maxRequestBufferSize)
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
if (useConnectionAdapter)
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
listenOptions.UsePassThrough();
|
||||
}
|
||||
});
|
||||
options.Listen(new IPEndPoint(IPAddress.Loopback, 0), listenOptions =>
|
||||
{
|
||||
if (useConnectionAdapter)
|
||||
{
|
||||
listenOptions.UsePassThrough();
|
||||
}
|
||||
});
|
||||
|
||||
options.Limits.MaxRequestBufferSize = maxRequestBufferSize;
|
||||
options.Limits.MaxRequestBufferSize = maxRequestBufferSize;
|
||||
|
||||
if (maxRequestBufferSize.HasValue &&
|
||||
maxRequestBufferSize.Value < options.Limits.MaxRequestLineSize)
|
||||
{
|
||||
options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize;
|
||||
}
|
||||
if (maxRequestBufferSize.HasValue &&
|
||||
maxRequestBufferSize.Value < options.Limits.MaxRequestLineSize)
|
||||
{
|
||||
options.Limits.MaxRequestLineSize = (int)maxRequestBufferSize;
|
||||
}
|
||||
|
||||
if (maxRequestBufferSize.HasValue &&
|
||||
maxRequestBufferSize.Value < options.Limits.MaxRequestHeadersTotalSize)
|
||||
{
|
||||
options.Limits.MaxRequestHeadersTotalSize = (int)maxRequestBufferSize;
|
||||
}
|
||||
if (maxRequestBufferSize.HasValue &&
|
||||
maxRequestBufferSize.Value < options.Limits.MaxRequestHeadersTotalSize)
|
||||
{
|
||||
options.Limits.MaxRequestHeadersTotalSize = (int)maxRequestBufferSize;
|
||||
}
|
||||
|
||||
options.Limits.MinRequestBodyDataRate = null;
|
||||
options.Limits.MinRequestBodyDataRate = null;
|
||||
|
||||
options.Limits.MaxRequestBodySize = _dataLength;
|
||||
options.Limits.MaxRequestBodySize = _dataLength;
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
await startReadingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
|
||||
|
||||
var buffer = new byte[expectedBody.Length];
|
||||
var bytesRead = 0;
|
||||
while (bytesRead < buffer.Length)
|
||||
{
|
||||
bytesRead += await context.Request.Body.ReadAsync(buffer, bytesRead, buffer.Length - bytesRead);
|
||||
}
|
||||
|
||||
await clientFinishedSendingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
|
||||
|
||||
// Verify client didn't send extra bytes
|
||||
if (await context.Request.Body.ReadAsync(new byte[1], 0, 1) != 0)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length");
|
||||
return;
|
||||
}
|
||||
|
||||
await context.Response.WriteAsync($"bytesRead: {bytesRead.ToString()}");
|
||||
}));
|
||||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
await startReadingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
|
||||
|
||||
var buffer = new byte[expectedBody.Length];
|
||||
var bytesRead = 0;
|
||||
while (bytesRead < buffer.Length)
|
||||
{
|
||||
bytesRead += await context.Request.Body.ReadAsync(buffer, bytesRead, buffer.Length - bytesRead);
|
||||
}
|
||||
|
||||
await clientFinishedSendingRequestBody.Task.TimeoutAfter(TimeSpan.FromSeconds(120));
|
||||
|
||||
// Verify client didn't send extra bytes
|
||||
if (await context.Request.Body.ReadAsync(new byte[1], 0, 1) != 0)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
await context.Response.WriteAsync("Client sent more bytes than expectedBody.Length");
|
||||
return;
|
||||
}
|
||||
|
||||
await context.Response.WriteAsync($"bytesRead: {bytesRead.ToString()}");
|
||||
}))
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Build();
|
||||
|
||||
await host.StartAsync();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
|||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -55,39 +56,43 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
Assert.True(contentLength % bufferLength == 0, $"{nameof(contentLength)} sent must be evenly divisible by {bufferLength}.");
|
||||
Assert.True(bufferLength % 256 == 0, $"{nameof(bufferLength)} must be evenly divisible by 256");
|
||||
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel(options =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Limits.MaxRequestBodySize = contentLength;
|
||||
options.Limits.MinRequestBodyDataRate = null;
|
||||
})
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
// Read the full request body
|
||||
long total = 0;
|
||||
var receivedBytes = new byte[bufferLength];
|
||||
var received = 0;
|
||||
while ((received = await context.Request.Body.ReadAsync(receivedBytes, 0, receivedBytes.Length)) > 0)
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
if (checkBytes)
|
||||
options.Limits.MaxRequestBodySize = contentLength;
|
||||
options.Limits.MinRequestBodyDataRate = null;
|
||||
})
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
for (var i = 0; i < received; i++)
|
||||
// Read the full request body
|
||||
long total = 0;
|
||||
var receivedBytes = new byte[bufferLength];
|
||||
var received = 0;
|
||||
while ((received = await context.Request.Body.ReadAsync(receivedBytes, 0, receivedBytes.Length)) > 0)
|
||||
{
|
||||
// Do not use Assert.Equal here, it is to slow for this hot path
|
||||
Assert.True((byte)((total + i) % 256) == receivedBytes[i], "Data received is incorrect");
|
||||
if (checkBytes)
|
||||
{
|
||||
for (var i = 0; i < received; i++)
|
||||
{
|
||||
// Do not use Assert.Equal here, it is to slow for this hot path
|
||||
Assert.True((byte)((total + i) % 256) == receivedBytes[i], "Data received is incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
total += received;
|
||||
}
|
||||
}
|
||||
|
||||
total += received;
|
||||
}
|
||||
|
||||
await context.Response.WriteAsync($"bytesRead: {total.ToString()}");
|
||||
});
|
||||
});
|
||||
await context.Response.WriteAsync($"bytesRead: {total.ToString()}");
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
{
|
||||
|
|
@ -140,17 +145,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Fact]
|
||||
public async Task DoesNotHangOnConnectionCloseRequest()
|
||||
{
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
await context.Response.WriteAsync("hello, world");
|
||||
});
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
await context.Response.WriteAsync("hello, world");
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
using (var client = new HttpClient())
|
||||
|
|
@ -173,7 +182,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var requestNumber = 0;
|
||||
var ensureConcurrentRequestTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
if (Interlocked.Increment(ref requestNumber) == 1)
|
||||
{
|
||||
|
|
@ -210,7 +219,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
"",
|
||||
"");
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +253,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
};
|
||||
|
||||
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||
await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -260,8 +268,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
// is still in flight when the connection is aborted, leading to the reset never being received
|
||||
// and therefore not logged.
|
||||
Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout));
|
||||
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
Assert.False(loggedHigherThanDebug);
|
||||
|
|
@ -293,7 +299,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
};
|
||||
|
||||
using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||
await using (var server = new TestServer(context => Task.CompletedTask, new TestServiceContext(LoggerFactory)))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -321,7 +327,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
// is still in flight when the connection is aborted, leading to the reset never being received
|
||||
// and therefore not logged.
|
||||
Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout));
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
Assert.False(loggedHigherThanDebug);
|
||||
|
|
@ -355,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
};
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
requestStarted.Release();
|
||||
await connectionClosing.WaitAsync();
|
||||
|
|
@ -378,7 +383,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
// and therefore not logged.
|
||||
Assert.True(await connectionReset.WaitAsync(TestConstants.DefaultTimeout), "Connection reset event should have been logged");
|
||||
connectionClosing.Release();
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
Assert.False(loggedHigherThanDebug, "Logged event should not have been higher than debug.");
|
||||
|
|
@ -392,26 +396,30 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var appDone = new SemaphoreSlim(0);
|
||||
var expectedExceptionThrown = false;
|
||||
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app => app.Run(async context =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
requestStarted.Release();
|
||||
Assert.True(await connectionReset.WaitAsync(_semaphoreWaitTimeout));
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
requestStarted.Release();
|
||||
Assert.True(await connectionReset.WaitAsync(_semaphoreWaitTimeout));
|
||||
|
||||
try
|
||||
{
|
||||
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||
}
|
||||
catch (ConnectionResetException)
|
||||
{
|
||||
expectedExceptionThrown = true;
|
||||
}
|
||||
try
|
||||
{
|
||||
await context.Request.Body.ReadAsync(new byte[1], 0, 1);
|
||||
}
|
||||
catch (ConnectionResetException)
|
||||
{
|
||||
expectedExceptionThrown = true;
|
||||
}
|
||||
|
||||
appDone.Release();
|
||||
}));
|
||||
appDone.Release();
|
||||
}));
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
{
|
||||
|
|
@ -439,18 +447,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
{
|
||||
var appStarted = new SemaphoreSlim(0);
|
||||
var requestAborted = new SemaphoreSlim(0);
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app => app.Run(async context =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
appStarted.Release();
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
appStarted.Release();
|
||||
|
||||
var token = context.RequestAborted;
|
||||
token.Register(() => requestAborted.Release(2));
|
||||
await requestAborted.WaitAsync().DefaultTimeout();
|
||||
}));
|
||||
var token = context.RequestAborted;
|
||||
token.Register(() => requestAborted.Release(2));
|
||||
await requestAborted.WaitAsync().DefaultTimeout();
|
||||
}));
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
{
|
||||
|
|
@ -472,15 +484,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Fact]
|
||||
public async Task AbortingTheConnectionSendsFIN()
|
||||
{
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app => app.Run(context =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
context.Abort();
|
||||
return Task.CompletedTask;
|
||||
}));
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Configure(app => app.Run(context =>
|
||||
{
|
||||
context.Abort();
|
||||
return Task.CompletedTask;
|
||||
}));
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
{
|
||||
|
|
@ -507,7 +523,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var appStartedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
appStartedTcs.SetResult();
|
||||
|
||||
|
|
@ -531,7 +547,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
await connectionClosedTcs.Task.DefaultTimeout();
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -542,7 +557,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var testContext = new TestServiceContext(LoggerFactory);
|
||||
var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
var connectionLifetimeFeature = context.Features.Get<IConnectionLifetimeFeature>();
|
||||
connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult());
|
||||
|
|
@ -568,7 +583,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
"",
|
||||
"");
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -579,7 +593,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var testContext = new TestServiceContext(LoggerFactory);
|
||||
var connectionClosedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
var connectionLifetimeFeature = context.Features.Get<IConnectionLifetimeFeature>();
|
||||
connectionLifetimeFeature.ConnectionClosed.Register(() => connectionClosedTcs.SetResult());
|
||||
|
|
@ -610,7 +624,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
// isn't guaranteed but not unexpected.
|
||||
}
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -627,7 +640,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var registrationTcs = new TaskCompletionSource<int>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var requestId = 0;
|
||||
|
||||
using (var server = new TestServer(async httpContext =>
|
||||
await using (var server = new TestServer(async httpContext =>
|
||||
{
|
||||
requestId++;
|
||||
|
||||
|
|
@ -692,7 +705,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
"");
|
||||
await connection.WaitForConnectionClose();
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
await Assert.ThrowsAsync<TaskCanceledException>(async () => await readTcs.Task);
|
||||
|
|
@ -752,7 +764,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var scratchBuffer = new byte[maxRequestBufferSize * 8];
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
await clientClosedConnection.Task;
|
||||
|
||||
|
|
@ -781,7 +793,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
clientClosedConnection.SetResult();
|
||||
|
||||
await appFuncCompleted.Task.DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny<string>()), Times.Once());
|
||||
|
|
@ -799,7 +810,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var scratchBuffer = new byte[4096];
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
appStartedTcs.SetResult();
|
||||
|
||||
|
|
@ -834,7 +845,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
|
||||
await Assert.ThrowsAnyAsync<IOException>(() => readTcs.Task).DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny<string>()), Times.Once());
|
||||
|
|
@ -842,24 +852,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress)
|
||||
{
|
||||
var builder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://{registerAddress}:0")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app =>
|
||||
var builder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var connection = context.Connection;
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(new
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls($"http://{registerAddress}:0")
|
||||
.Configure(app =>
|
||||
{
|
||||
RemoteIPAddress = connection.RemoteIpAddress?.ToString(),
|
||||
RemotePort = connection.RemotePort,
|
||||
LocalIPAddress = connection.LocalIpAddress?.ToString(),
|
||||
LocalPort = connection.LocalPort
|
||||
}));
|
||||
});
|
||||
});
|
||||
app.Run(async context =>
|
||||
{
|
||||
var connection = context.Connection;
|
||||
await context.Response.WriteAsync(JsonConvert.SerializeObject(new
|
||||
{
|
||||
RemoteIPAddress = connection.RemoteIpAddress?.ToString(),
|
||||
RemotePort = connection.RemotePort,
|
||||
LocalIPAddress = connection.LocalIpAddress?.ToString(),
|
||||
LocalPort = connection.LocalPort
|
||||
}));
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = builder.Build())
|
||||
using (var client = new HttpClient())
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Https;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Tests;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
|
@ -42,28 +43,32 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Fact]
|
||||
public async Task LargeDownload()
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
var bytes = new byte[1024];
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.Configure(app =>
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
app.Run(async context =>
|
||||
{
|
||||
var bytes = new byte[1024];
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
bytes[i] = (byte)i;
|
||||
}
|
||||
|
||||
context.Response.ContentLength = bytes.Length * 1024;
|
||||
context.Response.ContentLength = bytes.Length * 1024;
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
{
|
||||
await context.Response.BodyWriter.WriteAsync(new Memory<byte>(bytes, 0, bytes.Length));
|
||||
}
|
||||
});
|
||||
});
|
||||
for (int i = 0; i < 1024; i++)
|
||||
{
|
||||
await context.Response.BodyWriter.WriteAsync(new Memory<byte>(bytes, 0, bytes.Length));
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -96,19 +101,23 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
[Theory, MemberData(nameof(NullHeaderData))]
|
||||
public async Task IgnoreNullHeaderValues(string headerName, StringValues headerValue, string expectedValue)
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
context.Response.Headers.Add(headerName, headerValue);
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseUrls("http://127.0.0.1:0/")
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
context.Response.Headers.Add(headerName, headerValue);
|
||||
|
||||
await context.Response.WriteAsync("");
|
||||
});
|
||||
});
|
||||
await context.Response.WriteAsync("");
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -143,7 +152,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var requestStarted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var appCompleted = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(async httpContext =>
|
||||
await using (var server = new TestServer(async httpContext =>
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -175,7 +184,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
connectionClosed.SetResult();
|
||||
|
||||
await appCompleted.Task.DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
var requestAbortedWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var requestStartWh = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
using (var server = new TestServer(async httpContext =>
|
||||
await using (var server = new TestServer(async httpContext =>
|
||||
{
|
||||
requestStartWh.SetResult();
|
||||
|
||||
|
|
@ -239,7 +247,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
// RequestAborted tripped
|
||||
await requestAbortedWh.Task.DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +293,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var scratchBuffer = new byte[maxRequestBufferSize * 8];
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
context.RequestAborted.Register(() => requestAborted.SetResult());
|
||||
|
||||
|
|
@ -331,7 +338,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
clientClosedConnection.SetResult();
|
||||
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => writeTcs.Task).DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ConnectionStop(It.IsAny<string>()), Times.Once());
|
||||
|
|
@ -354,7 +360,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
var scratchBuffer = new byte[responseBodySegmentSize];
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
context.RequestAborted.Register(() => requestAborted.SetResult());
|
||||
|
||||
|
|
@ -398,7 +404,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
// On macOS, the default 5 shutdown timeout is insufficient for the write loop to complete, so give it extra time.
|
||||
await appCompletedTcs.Task.DefaultTimeout();
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
var coreLogs = TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel");
|
||||
|
|
@ -421,7 +426,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
// There's not guarantee that the app even gets invoked in this test. The connection reset can be observed
|
||||
// as early as accept.
|
||||
var testServiceContext = new TestServiceContext(LoggerFactory);
|
||||
using (var server = new TestServer(context => Task.CompletedTask, testServiceContext, listenOptions))
|
||||
await using (var server = new TestServer(context => Task.CompletedTask, testServiceContext, listenOptions))
|
||||
{
|
||||
for (var i = 0; i < numConnections; i++)
|
||||
{
|
||||
|
|
@ -436,7 +441,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
connection.Reset();
|
||||
}
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
var transportLogs = TestSink.Writes.Where(w => w.LoggerName == "Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv" ||
|
||||
|
|
@ -521,7 +525,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
}
|
||||
|
||||
using (var server = new TestServer(App, testContext))
|
||||
await using (var server = new TestServer(App, testContext))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -546,7 +550,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
sw.Stop();
|
||||
logger.LogInformation("Connection was aborted after {totalMilliseconds}ms.", sw.ElapsedMilliseconds);
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -590,7 +593,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
listenOptions.UseHttps(new HttpsConnectionAdapterOptions { ServerCertificate = certificate });
|
||||
}
|
||||
|
||||
using (var server = new TestServer(async context =>
|
||||
await using (var server = new TestServer(async context =>
|
||||
{
|
||||
context.RequestAborted.Register(() =>
|
||||
{
|
||||
|
|
@ -634,7 +637,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await AssertStreamAborted(connection.Stream, chunkSize * chunks);
|
||||
}
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -699,7 +701,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
copyToAsyncCts.SetException(new Exception("This shouldn't be reached."));
|
||||
}
|
||||
|
||||
using (var server = new TestServer(App, testContext, listenOptions))
|
||||
await using (var server = new TestServer(App, testContext, listenOptions))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -728,7 +730,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => copyToAsyncCts.Task).DefaultTimeout();
|
||||
await AssertStreamAborted(connection.Stream, responseSize);
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -776,7 +777,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
appFuncCompleted.SetResult();
|
||||
}
|
||||
|
||||
using (var server = new TestServer(App, testContext, listenOptions))
|
||||
await using (var server = new TestServer(App, testContext, listenOptions))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -802,7 +803,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
connection.ShutdownSend();
|
||||
await connection.WaitForConnectionClose();
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ResponseMinimumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
|
|
@ -854,7 +854,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await context.Response.BodyWriter.FlushAsync();
|
||||
}
|
||||
|
||||
using (var server = new TestServer(App, testContext, listenOptions))
|
||||
await using (var server = new TestServer(App, testContext, listenOptions))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -889,8 +889,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
connection.ShutdownSend();
|
||||
await connection.WaitForConnectionClose();
|
||||
}
|
||||
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ResponseMinimumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
|
|
@ -942,7 +940,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
appFuncCompleted.SetResult();
|
||||
}
|
||||
|
||||
using (var server = new TestServer(App, testContext, listenOptions))
|
||||
await using (var server = new TestServer(App, testContext, listenOptions))
|
||||
{
|
||||
using (var connection = server.CreateConnection())
|
||||
{
|
||||
|
|
@ -967,7 +965,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
await AssertStreamCompletedAtTargetRate(connection.Stream, expectedBytes: 33_553_556, targetBytesPerSecond);
|
||||
await appFuncCompleted.Task.DefaultTimeout();
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
mockKestrelTrace.Verify(t => t.ResponseMinimumDataRateNotSatisfied(It.IsAny<string>(), It.IsAny<string>()), Times.Never());
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
|
@ -72,16 +73,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
}
|
||||
}
|
||||
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseKestrel(o =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
o.ListenUnixSocket(path, builder =>
|
||||
{
|
||||
builder.Run(EchoServer);
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(o =>
|
||||
{
|
||||
o.ListenUnixSocket(path, builder =>
|
||||
{
|
||||
builder.Run(EchoServer);
|
||||
});
|
||||
})
|
||||
.Configure(c => { });
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(c => { });
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -100,7 +105,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
{
|
||||
var bytesReceived = await socket.ReceiveAsync(buffer.AsMemory(read, buffer.Length - read), SocketFlags.None).DefaultTimeout();
|
||||
read += bytesReceived;
|
||||
if (bytesReceived <= 0) break;
|
||||
if (bytesReceived <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Equal(data, buffer);
|
||||
|
|
@ -134,17 +142,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
|
||||
try
|
||||
{
|
||||
var hostBuilder = TransportSelector.GetWebHostBuilder()
|
||||
.UseUrls(url)
|
||||
.UseKestrel()
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app =>
|
||||
var hostBuilder = TransportSelector.GetHostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
await context.Response.WriteAsync("Hello World");
|
||||
});
|
||||
});
|
||||
webHostBuilder
|
||||
.UseUrls(url)
|
||||
.UseKestrel()
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
await context.Response.WriteAsync("Hello World");
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
@ -165,7 +177,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
|||
{
|
||||
var bytesReceived = await socket.ReceiveAsync(readBuffer.AsMemory(read), SocketFlags.None).DefaultTimeout();
|
||||
read += bytesReceived;
|
||||
if (bytesReceived <= 0) break;
|
||||
if (bytesReceived <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var httpResponse = Encoding.ASCII.GetString(readBuffer, 0, read);
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
|||
}
|
||||
}
|
||||
|
||||
Assert.All(TestSink.Writes, w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Debug));
|
||||
Assert.All(TestSink.Writes.Where(w => w.LoggerName != "Microsoft.Hosting.Lifetime"), w => Assert.InRange(w.LogLevel, LogLevel.Trace, LogLevel.Debug));
|
||||
Assert.Contains(TestSink.Writes, w => w.EventId.Id == 17);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,10 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
using BadHttpRequestException = Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException;
|
||||
|
||||
|
|
@ -686,7 +684,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
|||
"",
|
||||
"");
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -993,7 +990,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
|||
"",
|
||||
"Hello World");
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1065,7 +1061,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
|||
{
|
||||
var testContext = new TestServiceContext(LoggerFactory);
|
||||
|
||||
using (var server = new TestServer(async httpContext =>
|
||||
await using (var server = new TestServer(async httpContext =>
|
||||
{
|
||||
var response = httpContext.Response;
|
||||
var request = httpContext.Request;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Http.Features;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.Http2
|
|||
[SkipOnHelix("Ubuntu 20.04 disables TLS1.1 by default which SslStream requires in this scenario", Queues = "Ubuntu.2004.Amd64.Open")]
|
||||
public async Task TlsHandshakeRejectsTlsLessThan12()
|
||||
{
|
||||
using (var server = new TestServer(context =>
|
||||
await using (var server = new TestServer(context =>
|
||||
{
|
||||
var tlsFeature = context.Features.Get<ITlsApplicationProtocolFeature>();
|
||||
Assert.NotNull(tlsFeature);
|
||||
|
|
@ -66,7 +66,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.Http2
|
|||
await WaitForConnectionErrorAsync(reader, ignoreNonGoAwayFrames: false, expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.INADEQUATE_SECURITY);
|
||||
reader.Complete();
|
||||
}
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Http.Features;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Http.Features;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
using BadHttpRequestException = Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Serilog;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
||||
|
|
|
|||
|
|
@ -3410,8 +3410,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
|
|||
"",
|
||||
"Hello World!");
|
||||
}
|
||||
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Http;
|
|||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTransport
|
||||
|
|
@ -23,12 +24,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
|
|||
/// <summary>
|
||||
/// In-memory TestServer
|
||||
/// </summary
|
||||
internal class TestServer : IAsyncDisposable, IDisposable, IStartup
|
||||
internal class TestServer : IAsyncDisposable, IStartup
|
||||
{
|
||||
private readonly MemoryPool<byte> _memoryPool;
|
||||
private readonly RequestDelegate _app;
|
||||
private readonly InMemoryTransportFactory _transportFactory;
|
||||
private readonly IWebHost _host;
|
||||
private readonly IHost _host;
|
||||
|
||||
public TestServer(RequestDelegate app)
|
||||
: this(app, new TestServiceContext())
|
||||
|
|
@ -69,8 +70,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
|
|||
_transportFactory = new InMemoryTransportFactory();
|
||||
HttpClientSlim = new InMemoryHttpClientSlim(this);
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseSetting(WebHostDefaults.ShutdownTimeoutKey, TestConstants.DefaultTimeout.TotalSeconds.ToString())
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseSetting(WebHostDefaults.ShutdownTimeoutKey, TestConstants.DefaultTimeout.TotalSeconds.ToString())
|
||||
.Configure(app => { app.Run(_app); });
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
configureServices(services);
|
||||
|
|
@ -108,11 +114,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
|
|||
return _host.StopAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_host.Dispose();
|
||||
_memoryPool.Dispose();
|
||||
}
|
||||
|
||||
void IStartup.Configure(IApplicationBuilder app)
|
||||
{
|
||||
|
|
@ -126,8 +127,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests.TestTrans
|
|||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
// The concrete WebHost implements IAsyncDisposable
|
||||
await ((IAsyncDisposable)_host).ConfigureAwait(false).DisposeAsync();
|
||||
await _host.StopAsync().ConfigureAwait(false);
|
||||
// The concrete Host implements IAsyncDisposable
|
||||
await ((IAsyncDisposable)_host).DisposeAsync().ConfigureAwait(false);
|
||||
_memoryPool.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
|
|
@ -46,7 +47,7 @@ namespace Interop.FunctionalTests
|
|||
StartupLogPath = Path.Combine(ResolvedLogOutputDirectory, $"{ResolvedTestMethodName}.su.json");
|
||||
ShutdownLogPath = Path.Combine(ResolvedLogOutputDirectory, $"{ResolvedTestMethodName}.sd.json");
|
||||
|
||||
ChromeArgs = new [] {
|
||||
ChromeArgs = new[] {
|
||||
$"--headless",
|
||||
$"--no-sandbox",
|
||||
$"--disable-gpu",
|
||||
|
|
@ -62,7 +63,7 @@ namespace Interop.FunctionalTests
|
|||
};
|
||||
}
|
||||
|
||||
[ConditionalTheory(Skip="Disabling while debugging. https://github.com/dotnet/aspnetcore-internal/issues/1363")]
|
||||
[ConditionalTheory(Skip = "Disabling while debugging. https://github.com/dotnet/aspnetcore-internal/issues/1363")]
|
||||
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Missing SslStream ALPN support: https://github.com/dotnet/corefx/issues/30492")]
|
||||
[MinimumOSVersion(OperatingSystems.Windows, WindowsVersions.Win81, SkipReason = "Missing Windows ALPN support: https://en.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation#Support")]
|
||||
[InlineData("", "Interop HTTP/2 GET")]
|
||||
|
|
@ -71,27 +72,31 @@ namespace Interop.FunctionalTests
|
|||
{
|
||||
InitializeArgs();
|
||||
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
});
|
||||
})
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
if (HttpMethods.IsPost(context.Request.Query["TestMethod"]))
|
||||
{
|
||||
await context.Response.WriteAsync(_postHtml);
|
||||
}
|
||||
else
|
||||
{
|
||||
await context.Response.WriteAsync($"Interop {context.Request.Protocol} {context.Request.Method}");
|
||||
}
|
||||
}));
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(app => app.Run(async context =>
|
||||
{
|
||||
if (HttpMethods.IsPost(context.Request.Query["TestMethod"]))
|
||||
{
|
||||
await context.Response.WriteAsync(_postHtml);
|
||||
}
|
||||
else
|
||||
{
|
||||
await context.Response.WriteAsync($"Interop {context.Request.Protocol} {context.Request.Method}");
|
||||
}
|
||||
}));
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
|
@ -23,20 +24,24 @@ namespace Interop.FunctionalTests
|
|||
[MemberData(nameof(H2SpecTestCases))]
|
||||
public async Task RunIndividualTestCase(H2SpecTestCase testCase)
|
||||
{
|
||||
var hostBuilder = new WebHostBuilder()
|
||||
.UseKestrel(options =>
|
||||
var hostBuilder = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
if (testCase.Https)
|
||||
webHostBuilder
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
}
|
||||
});
|
||||
options.Listen(IPAddress.Loopback, 0, listenOptions =>
|
||||
{
|
||||
listenOptions.Protocols = HttpProtocols.Http2;
|
||||
if (testCase.Https)
|
||||
{
|
||||
listenOptions.UseHttps(TestResources.GetTestCertificate());
|
||||
}
|
||||
});
|
||||
})
|
||||
.Configure(ConfigureHelloWorld);
|
||||
})
|
||||
.ConfigureServices(AddTestLogging)
|
||||
.Configure(ConfigureHelloWorld);
|
||||
.ConfigureServices(AddTestLogging);
|
||||
|
||||
using (var host = hostBuilder.Build())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,20 +4,26 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||
{
|
||||
public static class TransportSelector
|
||||
{
|
||||
public static IWebHostBuilder GetWebHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
|
||||
public static IHostBuilder GetHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
|
||||
long? maxReadBufferSize = null)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
return new WebHostBuilder().UseLibuv(options =>
|
||||
{
|
||||
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
|
||||
options.MaxReadBufferSize = maxReadBufferSize;
|
||||
});
|
||||
return new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseLibuv(options =>
|
||||
{
|
||||
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
|
||||
options.MaxReadBufferSize = maxReadBufferSize;
|
||||
});
|
||||
});
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,25 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||
{
|
||||
public static class TransportSelector
|
||||
{
|
||||
public static IWebHostBuilder GetWebHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
|
||||
public static IHostBuilder GetHostBuilder(Func<MemoryPool<byte>> memoryPoolFactory = null,
|
||||
long? maxReadBufferSize = null)
|
||||
{
|
||||
return new WebHostBuilder().UseSockets(options =>
|
||||
{
|
||||
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
|
||||
options.MaxReadBufferSize = maxReadBufferSize;
|
||||
});
|
||||
return new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseSockets(options =>
|
||||
{
|
||||
options.MemoryPoolFactory = memoryPoolFactory ?? options.MemoryPoolFactory;
|
||||
options.MaxReadBufferSize = maxReadBufferSize;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue