Skip to content

Commit 4f60223

Browse files
author
N. Taylor Mullen
committed
Revert "Fix endpoint routing statefulness."
This reverts commit 9a6881b.
1 parent 4443115 commit 4f60223

File tree

2 files changed

+6
-42
lines changed

2 files changed

+6
-42
lines changed

src/Http/Routing/src/EndpointRoutingMiddleware.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public Task Invoke(HttpContext httpContext)
5151
if (endpoint != null)
5252
{
5353
Log.MatchSkipped(_logger, endpoint);
54-
55-
// Someone else set the endpoint, we'll let them handle the unsetting.
5654
return _next(httpContext);
5755
}
5856

@@ -89,7 +87,7 @@ static async Task AwaitMatch(EndpointRoutingMiddleware middleware, HttpContext h
8987
}
9088

9189
[MethodImpl(MethodImplOptions.AggressiveInlining)]
92-
private async Task SetRoutingAndContinue(HttpContext httpContext)
90+
private Task SetRoutingAndContinue(HttpContext httpContext)
9391
{
9492
// If there was no mutation of the endpoint then log failure
9593
var endpoint = httpContext.GetEndpoint();
@@ -109,16 +107,7 @@ private async Task SetRoutingAndContinue(HttpContext httpContext)
109107
Log.MatchSuccess(_logger, endpoint);
110108
}
111109

112-
try
113-
{
114-
await _next(httpContext);
115-
}
116-
finally
117-
{
118-
// We unset the endpoint after calling through to the next middleware. This enables any future calls into
119-
// endpoint routing don't no-op from there already being an endpoint set.
120-
httpContext.SetEndpoint(endpoint: null);
121-
}
110+
return _next(httpContext);
122111
}
123112

124113
// Initialization is async to avoid blocking threads while reflection and things

src/Http/Routing/test/UnitTests/EndpointRoutingMiddlewareTest.cs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,7 @@ namespace Microsoft.AspNetCore.Routing
2121
public class EndpointRoutingMiddlewareTest
2222
{
2323
[Fact]
24-
public async Task Invoke_OnException_ResetsEndpoint()
25-
{
26-
// Arrange
27-
var httpContext = CreateHttpContext();
28-
29-
var middleware = CreateMiddleware(next: context => throw new Exception());
30-
31-
// Act
32-
try
33-
{
34-
await middleware.Invoke(httpContext);
35-
}
36-
catch
37-
{
38-
// Do nothing, we expect the test to throw.
39-
}
40-
41-
// Assert
42-
var endpoint = httpContext.GetEndpoint();
43-
Assert.Null(endpoint);
44-
}
45-
46-
[Fact]
47-
public async Task Invoke_OnCall_SetsEndpointFeatureAndResetsEndpoint()
24+
public async Task Invoke_OnCall_SetsEndpointFeature()
4825
{
4926
// Arrange
5027
var httpContext = CreateHttpContext();
@@ -57,16 +34,14 @@ public async Task Invoke_OnCall_SetsEndpointFeatureAndResetsEndpoint()
5734
// Assert
5835
var endpointFeature = httpContext.Features.Get<IEndpointFeature>();
5936
Assert.NotNull(endpointFeature);
60-
Assert.Null(endpointFeature.Endpoint);
6137
}
6238

6339
[Fact]
64-
public async Task Invoke_SkipsRoutingAndMaintainsEndpoint_IfEndpointSet()
40+
public async Task Invoke_SkipsRouting_IfEndpointSet()
6541
{
6642
// Arrange
6743
var httpContext = CreateHttpContext();
68-
var expectedEndpoint = new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "myapp");
69-
httpContext.SetEndpoint(expectedEndpoint);
44+
httpContext.SetEndpoint(new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "myapp"));
7045

7146
var middleware = CreateMiddleware();
7247

@@ -75,7 +50,7 @@ public async Task Invoke_SkipsRoutingAndMaintainsEndpoint_IfEndpointSet()
7550

7651
// Assert
7752
var endpoint = httpContext.GetEndpoint();
78-
Assert.Same(expectedEndpoint, endpoint);
53+
Assert.NotNull(endpoint);
7954
Assert.Equal("myapp", endpoint.DisplayName);
8055
}
8156

0 commit comments

Comments
 (0)