diff --git a/samples/HttpOverridesSample/Startup.cs b/samples/HttpOverridesSample/Startup.cs index dc4e4ccddb..4c71f32a93 100644 --- a/samples/HttpOverridesSample/Startup.cs +++ b/samples/HttpOverridesSample/Startup.cs @@ -31,6 +31,14 @@ namespace HttpOverridesSample } // Entry point for the application. - public static void Main(string[] args) => WebApplication.Run(args); + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/ResponseBufferingSample/Properties/launchSettings.json b/samples/ResponseBufferingSample/Properties/launchSettings.json index 0e57697bac..2555984271 100644 --- a/samples/ResponseBufferingSample/Properties/launchSettings.json +++ b/samples/ResponseBufferingSample/Properties/launchSettings.json @@ -1,4 +1,12 @@ { + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49657/", + "sslPort": 0 + } + }, "profiles": { "IIS Express": { "commandName": "IISExpress", @@ -9,13 +17,9 @@ }, "web": { "commandName": "web", - "launchBrowser": true, - "launchUrl": "http://localhost:5000/" - }, - "kestrel": { - "commandName": "kestrel", - "launchBrowser": true, - "launchUrl": "http://localhost:5001/" + "environmentVariables": { + "Hosting:Environment": "Development" + } } } } \ No newline at end of file diff --git a/samples/ResponseBufferingSample/Startup.cs b/samples/ResponseBufferingSample/Startup.cs index db8b7d9eca..78f824dce4 100644 --- a/samples/ResponseBufferingSample/Startup.cs +++ b/samples/ResponseBufferingSample/Startup.cs @@ -1,4 +1,5 @@ using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; @@ -32,5 +33,16 @@ namespace ResponseBufferingSample await context.Response.WriteAsync("Hi Bob!"); }); } + + // Entry point for the application. + public static void Main(string[] args) + { + var application = new WebApplicationBuilder() + .UseConfiguration(WebApplicationConfiguration.GetDefault(args)) + .UseStartup() + .Build(); + + application.Run(); + } } } diff --git a/samples/ResponseBufferingSample/hosting.json b/samples/ResponseBufferingSample/hosting.json new file mode 100644 index 0000000000..f8ef14574d --- /dev/null +++ b/samples/ResponseBufferingSample/hosting.json @@ -0,0 +1,3 @@ +{ + "server": "Microsoft.AspNet.Server.Kestrel" +} diff --git a/samples/ResponseBufferingSample/project.json b/samples/ResponseBufferingSample/project.json index f43d9ec282..08e998cddf 100644 --- a/samples/ResponseBufferingSample/project.json +++ b/samples/ResponseBufferingSample/project.json @@ -1,15 +1,14 @@ { - "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { - "Kestrel": "1.0.0-*", "Microsoft.AspNet.Buffering": "1.0.0-*", - "Microsoft.AspNet.Server.IIS": "1.0.0-*", - "Microsoft.AspNet.Server.WebListener": "1.0.0-*" + "Microsoft.AspNet.Server.Kestrel": "1.0.0-*" + }, + "compilationOptions": { + "emitEntryPoint": true }, "commands": { - "web": "Microsoft.AspNet.Server.WebListener --server.urls=http://localhost:5000", - "kestrel": "Kestrel --server.urls=http://localhost:5001" + "web": "ResponseBufferingSample" }, "frameworks": { "dnx451": { }, diff --git a/samples/ResponseBufferingSample/wwwroot/web.config b/samples/ResponseBufferingSample/wwwroot/web.config new file mode 100644 index 0000000000..9a0d90abf8 --- /dev/null +++ b/samples/ResponseBufferingSample/wwwroot/web.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Buffering.Tests/ResponseBufferingMiddlewareTests.cs b/test/Microsoft.AspNet.Buffering.Tests/ResponseBufferingMiddlewareTests.cs index 5569a14222..fc07df25ec 100644 --- a/test/Microsoft.AspNet.Buffering.Tests/ResponseBufferingMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Buffering.Tests/ResponseBufferingMiddlewareTests.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.TestHost; @@ -19,18 +20,20 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task BufferResponse_SetsContentLength() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); - await context.Response.WriteAsync("Hello World"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + app.UseResponseBuffering(); + app.Run(async context => + { + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + await context.Response.WriteAsync("Hello World"); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -45,19 +48,21 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task BufferResponseWithManualContentLength_NotReplaced() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - context.Response.ContentLength = 12; - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); - await context.Response.WriteAsync("Hello World"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + app.UseResponseBuffering(); + app.Run(async context => + { + context.Response.ContentLength = 12; + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + await context.Response.WriteAsync("Hello World"); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -71,36 +76,38 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task Seek_AllowsResttingBuffer() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - var body = context.Response.Body; - Assert.False(context.Response.HasStarted); - Assert.True(body.CanSeek); - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + app.UseResponseBuffering(); + app.Run(async context => + { + var body = context.Response.Body; + Assert.False(context.Response.HasStarted); + Assert.True(body.CanSeek); + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("Hello World"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); - Assert.Equal(11, body.Position); - Assert.Equal(11, body.Length); + await context.Response.WriteAsync("Hello World"); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + Assert.Equal(11, body.Position); + Assert.Equal(11, body.Length); - Assert.Throws(() => body.Seek(1, SeekOrigin.Begin)); - Assert.Throws(() => body.Seek(0, SeekOrigin.Current)); - Assert.Throws(() => body.Seek(0, SeekOrigin.End)); + Assert.Throws(() => body.Seek(1, SeekOrigin.Begin)); + Assert.Throws(() => body.Seek(0, SeekOrigin.Current)); + Assert.Throws(() => body.Seek(0, SeekOrigin.End)); - Assert.Equal(0, body.Seek(0, SeekOrigin.Begin)); - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + Assert.Equal(0, body.Seek(0, SeekOrigin.Begin)); + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("12345"); - Assert.Equal(5, body.Position); - Assert.Equal(5, body.Length); + await context.Response.WriteAsync("12345"); + Assert.Equal(5, body.Position); + Assert.Equal(5, body.Length); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -115,34 +122,36 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task SetPosition_AllowsResttingBuffer() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - var body = context.Response.Body; - Assert.False(context.Response.HasStarted); - Assert.True(body.CanSeek); - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + app.UseResponseBuffering(); + app.Run(async context => + { + var body = context.Response.Body; + Assert.False(context.Response.HasStarted); + Assert.True(body.CanSeek); + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("Hello World"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); - Assert.Equal(11, body.Position); - Assert.Equal(11, body.Length); + await context.Response.WriteAsync("Hello World"); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + Assert.Equal(11, body.Position); + Assert.Equal(11, body.Length); - Assert.Throws(() => body.Position = 1); + Assert.Throws(() => body.Position = 1); - body.Position = 0; - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + body.Position = 0; + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("12345"); - Assert.Equal(5, body.Position); - Assert.Equal(5, body.Length); + await context.Response.WriteAsync("12345"); + Assert.Equal(5, body.Position); + Assert.Equal(5, body.Length); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -157,34 +166,36 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task SetLength_AllowsResttingBuffer() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - var body = context.Response.Body; - Assert.False(context.Response.HasStarted); - Assert.True(body.CanSeek); - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + app.UseResponseBuffering(); + app.Run(async context => + { + var body = context.Response.Body; + Assert.False(context.Response.HasStarted); + Assert.True(body.CanSeek); + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("Hello World"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); - Assert.Equal(11, body.Position); - Assert.Equal(11, body.Length); + await context.Response.WriteAsync("Hello World"); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); + Assert.Equal(11, body.Position); + Assert.Equal(11, body.Length); - Assert.Throws(() => body.SetLength(1)); + Assert.Throws(() => body.SetLength(1)); - body.SetLength(0); - Assert.Equal(0, body.Position); - Assert.Equal(0, body.Length); + body.SetLength(0); + Assert.Equal(0, body.Position); + Assert.Equal(0, body.Length); - await context.Response.WriteAsync("12345"); - Assert.Equal(5, body.Position); - Assert.Equal(5, body.Length); + await context.Response.WriteAsync("12345"); + Assert.Equal(5, body.Position); + Assert.Equal(5, body.Length); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -199,27 +210,29 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task DisableBufferingViaFeature() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + app.UseResponseBuffering(); + app.Run(async context => + { + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); - var bufferingFeature = context.Features.Get(); - Assert.NotNull(bufferingFeature); - bufferingFeature.DisableResponseBuffering(); + var bufferingFeature = context.Features.Get(); + Assert.NotNull(bufferingFeature); + bufferingFeature.DisableResponseBuffering(); - Assert.False(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.False(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); - await context.Response.WriteAsync("Hello World"); + await context.Response.WriteAsync("Hello World"); - Assert.True(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.True(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -231,32 +244,34 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task DisableBufferingViaFeatureAfterFirstWrite_Flushes() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + app.UseResponseBuffering(); + app.Run(async context => + { + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); - await context.Response.WriteAsync("Hello"); + await context.Response.WriteAsync("Hello"); - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); - var bufferingFeature = context.Features.Get(); - Assert.NotNull(bufferingFeature); - bufferingFeature.DisableResponseBuffering(); + var bufferingFeature = context.Features.Get(); + Assert.NotNull(bufferingFeature); + bufferingFeature.DisableResponseBuffering(); - Assert.True(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.True(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); - await context.Response.WriteAsync(" World"); + await context.Response.WriteAsync(" World"); - Assert.True(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.True(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); @@ -268,25 +283,27 @@ namespace Microsoft.AspNet.Buffering.Tests [Fact] public async Task FlushDisablesBuffering() { - var server = TestServer.Create(app => - { - app.UseResponseBuffering(); - app.Run(async context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.False(context.Response.HasStarted); - Assert.True(context.Response.Body.CanSeek); + app.UseResponseBuffering(); + app.Run(async context => + { + Assert.False(context.Response.HasStarted); + Assert.True(context.Response.Body.CanSeek); - context.Response.Body.Flush(); + context.Response.Body.Flush(); - Assert.True(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.True(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); - await context.Response.WriteAsync("Hello World"); + await context.Response.WriteAsync("Hello World"); - Assert.True(context.Response.HasStarted); - Assert.False(context.Response.Body.CanSeek); + Assert.True(context.Response.HasStarted); + Assert.False(context.Response.Body.CanSeek); + }); }); - }); + var server = new TestServer(builder); var response = await server.CreateClient().GetAsync(""); response.EnsureSuccessStatusCode(); diff --git a/test/Microsoft.AspNet.HttpOverrides.Tests/HttpMethodOverrideMiddlewareTest.cs b/test/Microsoft.AspNet.HttpOverrides.Tests/HttpMethodOverrideMiddlewareTest.cs index de987a4e63..d077fac906 100644 --- a/test/Microsoft.AspNet.HttpOverrides.Tests/HttpMethodOverrideMiddlewareTest.cs +++ b/test/Microsoft.AspNet.HttpOverrides.Tests/HttpMethodOverrideMiddlewareTest.cs @@ -4,6 +4,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.TestHost; using Xunit; @@ -15,16 +16,18 @@ namespace Microsoft.AspNet.HttpOverrides public async Task XHttpMethodOverrideHeaderAvaiableChangesRequestMethod() { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseHttpMethodOverride(); - app.Run(context => + var builder = new WebApplicationBuilder() + .Configure(app => { - assertsExecuted = true; - Assert.Equal("DELETE", context.Request.Method); - return Task.FromResult(0); + app.UseHttpMethodOverride(); + app.Run(context => + { + assertsExecuted = true; + Assert.Equal("DELETE", context.Request.Method); + return Task.FromResult(0); + }); }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Post, ""); req.Headers.Add("X-Http-Method-Override", "DELETE"); @@ -36,16 +39,19 @@ namespace Microsoft.AspNet.HttpOverrides public async Task XHttpMethodOverrideHeaderUnavaiableDoesntChangeRequestMethod() { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseHttpMethodOverride(); - app.Run(context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.Equal("POST",context.Request.Method); - assertsExecuted = true; - return Task.FromResult(0); + app.UseHttpMethodOverride(); + app.Run(context => + { + Assert.Equal("POST",context.Request.Method); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - }); + var server = new TestServer(builder); + var req = new HttpRequestMessage(HttpMethod.Post, ""); await server.CreateClient().SendAsync(req); Assert.True(assertsExecuted); @@ -55,16 +61,19 @@ namespace Microsoft.AspNet.HttpOverrides public async Task XHttpMethodOverrideFromGetRequestDoesntChangeMethodType() { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseHttpMethodOverride(); - app.Run(context => + var builder = new WebApplicationBuilder() + .Configure(app => { - Assert.Equal("GET", context.Request.Method); - assertsExecuted = true; - return Task.FromResult(0); + app.UseHttpMethodOverride(); + app.Run(context => + { + Assert.Equal("GET", context.Request.Method); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - }); + var server = new TestServer(builder); + var req = new HttpRequestMessage(HttpMethod.Get, ""); await server.CreateClient().SendAsync(req); Assert.True(assertsExecuted); diff --git a/test/Microsoft.AspNet.HttpOverrides.Tests/OverrideHeaderMiddlewareTest.cs b/test/Microsoft.AspNet.HttpOverrides.Tests/OverrideHeaderMiddlewareTest.cs index 38db395f0a..b6ef29b458 100644 --- a/test/Microsoft.AspNet.HttpOverrides.Tests/OverrideHeaderMiddlewareTest.cs +++ b/test/Microsoft.AspNet.HttpOverrides.Tests/OverrideHeaderMiddlewareTest.cs @@ -4,6 +4,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.TestHost; using Xunit; @@ -16,19 +17,21 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.XForwardedFor; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.XForwardedFor; + }); + app.Run(context => + { + Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-For", "11.111.111.11"); @@ -41,19 +44,21 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.XForwardedFor; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.XForwardedFor; + }); + app.Run(context => + { + Assert.Null(context.Connection.RemoteIpAddress); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Null(context.Connection.RemoteIpAddress); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-For", "BAD-IP"); @@ -66,19 +71,21 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.XForwardedHost; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.XForwardedHost; + }); + app.Run(context => + { + Assert.Equal("testhost", context.Request.Host.ToString()); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Equal("testhost", context.Request.Host.ToString()); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-Host", "testhost"); @@ -91,19 +98,21 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.XForwardedProto; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.XForwardedProto; + }); + app.Run(context => + { + Assert.Equal("TestProtocol", context.Request.Scheme); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Equal("TestProtocol", context.Request.Scheme); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-Proto", "TestProtocol"); @@ -123,21 +132,23 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.All; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.All; + }); + app.Run(context => + { + Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); + Assert.Equal("testhost", context.Request.Host.ToString()); + Assert.Equal("Protocol", context.Request.Scheme); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); - Assert.Equal("testhost", context.Request.Host.ToString()); - Assert.Equal("Protocol", context.Request.Scheme); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-For", "11.111.111.11"); @@ -152,21 +163,23 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.None; + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.None; + }); + app.Run(context => + { + Assert.Null(context.Connection.RemoteIpAddress); + Assert.Equal("localhost", context.Request.Host.ToString()); + Assert.Equal("http", context.Request.Scheme); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - app.Run(context => - { - Assert.Null(context.Connection.RemoteIpAddress); - Assert.Equal("localhost", context.Request.Host.ToString()); - Assert.Equal("http", context.Request.Scheme); - assertsExecuted = true; - return Task.FromResult(0); - }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-For", "11.111.111.11"); @@ -181,22 +194,24 @@ namespace Microsoft.AspNet.HttpOverrides { var assertsExecuted = false; - var server = TestServer.Create(app => - { - app.UseOverrideHeaders(options => + var builder = new WebApplicationBuilder() + .Configure(app => { - options.ForwardedOptions = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; - }); - app.Run(context => - { - Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); - Assert.Equal("localhost", context.Request.Host.ToString()); - Assert.Equal("Protocol", context.Request.Scheme); - assertsExecuted = true; - return Task.FromResult(0); + app.UseOverrideHeaders(options => + { + options.ForwardedOptions = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + }); + app.Run(context => + { + Assert.Equal("11.111.111.11", context.Connection.RemoteIpAddress.ToString()); + Assert.Equal("localhost", context.Request.Host.ToString()); + Assert.Equal("Protocol", context.Request.Scheme); + assertsExecuted = true; + return Task.FromResult(0); + }); }); - }); + var server = new TestServer(builder); var req = new HttpRequestMessage(HttpMethod.Get, ""); req.Headers.Add("X-Forwarded-For", "11.111.111.11");