Revert "Fix endpoint routing statefulness."

This reverts commit 9a6881b0e8.
This commit is contained in:
N. Taylor Mullen 2019-08-12 13:13:13 -07:00
parent 44431151c7
commit 4f6022323b
2 changed files with 6 additions and 42 deletions

View File

@ -51,8 +51,6 @@ namespace Microsoft.AspNetCore.Routing
if (endpoint != null) if (endpoint != null)
{ {
Log.MatchSkipped(_logger, endpoint); Log.MatchSkipped(_logger, endpoint);
// Someone else set the endpoint, we'll let them handle the unsetting.
return _next(httpContext); return _next(httpContext);
} }
@ -89,7 +87,7 @@ namespace Microsoft.AspNetCore.Routing
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private async Task SetRoutingAndContinue(HttpContext httpContext) private Task SetRoutingAndContinue(HttpContext httpContext)
{ {
// If there was no mutation of the endpoint then log failure // If there was no mutation of the endpoint then log failure
var endpoint = httpContext.GetEndpoint(); var endpoint = httpContext.GetEndpoint();
@ -109,16 +107,7 @@ namespace Microsoft.AspNetCore.Routing
Log.MatchSuccess(_logger, endpoint); Log.MatchSuccess(_logger, endpoint);
} }
try return _next(httpContext);
{
await _next(httpContext);
}
finally
{
// We unset the endpoint after calling through to the next middleware. This enables any future calls into
// endpoint routing don't no-op from there already being an endpoint set.
httpContext.SetEndpoint(endpoint: null);
}
} }
// Initialization is async to avoid blocking threads while reflection and things // Initialization is async to avoid blocking threads while reflection and things

View File

@ -21,30 +21,7 @@ namespace Microsoft.AspNetCore.Routing
public class EndpointRoutingMiddlewareTest public class EndpointRoutingMiddlewareTest
{ {
[Fact] [Fact]
public async Task Invoke_OnException_ResetsEndpoint() public async Task Invoke_OnCall_SetsEndpointFeature()
{
// Arrange
var httpContext = CreateHttpContext();
var middleware = CreateMiddleware(next: context => throw new Exception());
// Act
try
{
await middleware.Invoke(httpContext);
}
catch
{
// Do nothing, we expect the test to throw.
}
// Assert
var endpoint = httpContext.GetEndpoint();
Assert.Null(endpoint);
}
[Fact]
public async Task Invoke_OnCall_SetsEndpointFeatureAndResetsEndpoint()
{ {
// Arrange // Arrange
var httpContext = CreateHttpContext(); var httpContext = CreateHttpContext();
@ -57,16 +34,14 @@ namespace Microsoft.AspNetCore.Routing
// Assert // Assert
var endpointFeature = httpContext.Features.Get<IEndpointFeature>(); var endpointFeature = httpContext.Features.Get<IEndpointFeature>();
Assert.NotNull(endpointFeature); Assert.NotNull(endpointFeature);
Assert.Null(endpointFeature.Endpoint);
} }
[Fact] [Fact]
public async Task Invoke_SkipsRoutingAndMaintainsEndpoint_IfEndpointSet() public async Task Invoke_SkipsRouting_IfEndpointSet()
{ {
// Arrange // Arrange
var httpContext = CreateHttpContext(); var httpContext = CreateHttpContext();
var expectedEndpoint = new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "myapp"); httpContext.SetEndpoint(new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "myapp"));
httpContext.SetEndpoint(expectedEndpoint);
var middleware = CreateMiddleware(); var middleware = CreateMiddleware();
@ -75,7 +50,7 @@ namespace Microsoft.AspNetCore.Routing
// Assert // Assert
var endpoint = httpContext.GetEndpoint(); var endpoint = httpContext.GetEndpoint();
Assert.Same(expectedEndpoint, endpoint); Assert.NotNull(endpoint);
Assert.Equal("myapp", endpoint.DisplayName); Assert.Equal("myapp", endpoint.DisplayName);
} }