Skip to content

Commit 4443115

Browse files
author
N. Taylor Mullen
committed
Revert "Addressed code review comments."
This reverts commit 479d5ed.
1 parent 18391dd commit 4443115

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

src/Http/Routing/src/EndpointRoutingMiddleware.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Task Invoke(HttpContext httpContext)
5252
{
5353
Log.MatchSkipped(_logger, endpoint);
5454

55-
// Someone else set the endpoint, we'll let them handle the clearing of the endpoint.
55+
// Someone else set the endpoint, we'll let them handle the unsetting.
5656
return _next(httpContext);
5757
}
5858

@@ -88,6 +88,7 @@ static async Task AwaitMatch(EndpointRoutingMiddleware middleware, HttpContext h
8888

8989
}
9090

91+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9192
private async Task SetRoutingAndContinue(HttpContext httpContext)
9293
{
9394
// If there was no mutation of the endpoint then log failure
@@ -114,7 +115,8 @@ private async Task SetRoutingAndContinue(HttpContext httpContext)
114115
}
115116
finally
116117
{
117-
// This allows a second call in a single request (such as from the ErrorHandlerMiddleware) to perform routing again.
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.
118120
httpContext.SetEndpoint(endpoint: null);
119121
}
120122
}

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,6 @@ namespace Microsoft.AspNetCore.Routing
2020
{
2121
public class EndpointRoutingMiddlewareTest
2222
{
23-
[Fact]
24-
public async Task Invoke_ChangedPath_ResultsInDifferentResult()
25-
{
26-
// Arrange
27-
var httpContext = CreateHttpContext();
28-
var matcher = new Mock<Matcher>();
29-
var pathToEndpoints = new Dictionary<string, Endpoint>()
30-
{
31-
["/initial"] = new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "initialEndpoint"),
32-
["/changed"] = new Endpoint(c => Task.CompletedTask, new EndpointMetadataCollection(), "changedEndpoint")
33-
};
34-
matcher.Setup(m => m.MatchAsync(httpContext))
35-
.Callback<HttpContext>(context =>
36-
{
37-
var endpointToSet = pathToEndpoints[context.Request.Path];
38-
context.SetEndpoint(endpointToSet);
39-
})
40-
.Returns(Task.CompletedTask)
41-
.Verifiable();
42-
var matcherFactory = Mock.Of<MatcherFactory>(factory => factory.CreateMatcher(It.IsAny<EndpointDataSource>()) == matcher.Object);
43-
var middleware = CreateMiddleware(
44-
matcherFactory: matcherFactory,
45-
next: context =>
46-
{
47-
Assert.True(pathToEndpoints.TryGetValue(context.Request.Path, out var expectedEndpoint));
48-
49-
var currentEndpoint = context.GetEndpoint();
50-
Assert.Equal(expectedEndpoint, currentEndpoint);
51-
52-
return Task.CompletedTask;
53-
});
54-
55-
// Act
56-
httpContext.Request.Path = "/initial";
57-
await middleware.Invoke(httpContext);
58-
httpContext.Request.Path = "/changed";
59-
await middleware.Invoke(httpContext);
60-
61-
// Assert
62-
matcher.Verify();
63-
}
64-
6523
[Fact]
6624
public async Task Invoke_OnException_ResetsEndpoint()
6725
{

0 commit comments

Comments
 (0)