Support supression of matching for endpoints
This commit is contained in:
parent
085a0b808e
commit
97f54c532b
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Metadata used to prevent URL matching. The associated endpoint will not be
|
||||
/// considered URL matching for incoming requests.
|
||||
/// </summary>
|
||||
public interface ISuppressMatchingMetadata
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.Routing.Internal
|
|||
for (var i = 0; i < endpoints.Count; i++)
|
||||
{
|
||||
var endpoint = endpoints[i] as MatcherEndpoint;
|
||||
if (endpoint != null)
|
||||
if (endpoint != null && endpoint.Metadata.GetMetadata<ISuppressMatchingMetadata>() == null)
|
||||
{
|
||||
builder.AddEndpoint(endpoint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
|||
// register other endpoint types, which are non-routable, and it's
|
||||
// ok that we won't route to them.
|
||||
var endpoint = endpoints[i] as MatcherEndpoint;
|
||||
if (endpoint != null)
|
||||
if (endpoint != null && endpoint.Metadata.GetMetadata<ISuppressMatchingMetadata>() == null)
|
||||
{
|
||||
builder.AddEndpoint(endpoint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNetCore.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Metadata used to prevent URL matching. The associated endpoint will not be
|
||||
/// considered URL matching for incoming requests.
|
||||
/// </summary>
|
||||
public sealed class SuppressMatchingMetadata : ISuppressMatchingMetadata
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +67,27 @@ namespace Microsoft.AspNetCore.Routing.Matching
|
|||
Assert.Empty(inner.Endpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Matcher_Ignores_SuppressedEndpoint()
|
||||
{
|
||||
// Arrange
|
||||
var dataSource = new DynamicEndpointDataSource();
|
||||
var endpoint = new MatcherEndpoint(
|
||||
MatcherEndpoint.EmptyInvoker,
|
||||
RoutePatternFactory.Parse("/"),
|
||||
0,
|
||||
new EndpointMetadataCollection(new SuppressMatchingMetadata()),
|
||||
"test");
|
||||
dataSource.AddEndpoint(endpoint);
|
||||
|
||||
// Act
|
||||
var matcher = new DataSourceDependentMatcher(dataSource, TestMatcherBuilder.Create);
|
||||
|
||||
// Assert
|
||||
var inner = Assert.IsType<TestMatcher>(matcher.CurrentMatcher);
|
||||
Assert.Empty(inner.Endpoints);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cache_Reinitializes_WhenDataSourceChanges()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue