Reacting to new Hosting API
This commit is contained in:
parent
5e3c7cbbf0
commit
92fff3ccf3
|
|
@ -31,6 +31,14 @@ namespace HttpOverridesSample
|
|||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var application = new WebApplicationBuilder()
|
||||
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
application.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Startup>()
|
||||
.Build();
|
||||
|
||||
application.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"server": "Microsoft.AspNet.Server.Kestrel"
|
||||
}
|
||||
|
|
@ -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": { },
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
|
|
@ -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<ArgumentOutOfRangeException>(() => body.Seek(1, SeekOrigin.Begin));
|
||||
Assert.Throws<ArgumentException>(() => body.Seek(0, SeekOrigin.Current));
|
||||
Assert.Throws<ArgumentException>(() => body.Seek(0, SeekOrigin.End));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => body.Seek(1, SeekOrigin.Begin));
|
||||
Assert.Throws<ArgumentException>(() => body.Seek(0, SeekOrigin.Current));
|
||||
Assert.Throws<ArgumentException>(() => 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<ArgumentOutOfRangeException>(() => body.Position = 1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => 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<ArgumentOutOfRangeException>(() => body.SetLength(1));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => 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<IHttpBufferingFeature>();
|
||||
Assert.NotNull(bufferingFeature);
|
||||
bufferingFeature.DisableResponseBuffering();
|
||||
var bufferingFeature = context.Features.Get<IHttpBufferingFeature>();
|
||||
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<IHttpBufferingFeature>();
|
||||
Assert.NotNull(bufferingFeature);
|
||||
bufferingFeature.DisableResponseBuffering();
|
||||
var bufferingFeature = context.Features.Get<IHttpBufferingFeature>();
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue