-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Exclude regex and alpha constraints when SlimBuilder is used. #46227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mitchdenny
merged 40 commits into
dotnet:main
from
mitchdenny:exclude-regex-alpha-on-slim-builder
Feb 17, 2023
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
a7d32fd
Implement AddRoutingCore to support excluding Regex.
mitchdenny 473587b
Rename UseKestrel.
mitchdenny 63661ce
Add XML docs and API.
mitchdenny ea59a01
Merge branch 'main' into exclude-regex-alpha-on-slim-builder
mitchdenny e9ac4e7
Added test cases to cover removing regex.
mitchdenny 1d723ee
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny 008f937
Cleaned up some tests and added message assertion.
mitchdenny 50395a0
Merge branch 'exclude-regex-alpha-on-slim-builder' of https://github.…
mitchdenny fc44ea3
Remove AddRegexConstraint and use SetParameterPolicy instead.
mitchdenny 78056ab
Introduce dummy route constraint to give helpful error message.
mitchdenny ddf8fd9
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny 6c9d3d2
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny 3070320
Update src/Http/Routing/src/ParameterPolicyActivator.cs
mitchdenny e6d632f
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny 03bfcd9
Update src/Http/Routing/src/Resources.resx
mitchdenny 1c94ae4
Throw on first request.
mitchdenny d836911
Update src/Http/Routing/src/DependencyInjection/RoutingServiceCollect…
mitchdenny 233903a
Update src/Http/Routing/src/DependencyInjection/RoutingServiceCollect…
mitchdenny 91b00ab
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny a18ac7c
Rename AddRoutingCore to AddRoutingSlim.
mitchdenny a060ef7
Revert back to AddRoutingCore(...).
mitchdenny 44f29ef
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny 63b6f59
Update src/Http/Routing/src/DependencyInjection/RoutingServiceCollect…
mitchdenny bfcc4ff
Moved error stub to separate file.
mitchdenny 6c3f447
Applied Stephen's changes.
mitchdenny 5b36ab8
Responding to PR feedback around handling edge cases.
mitchdenny 346876a
Swap out call to AddRouting(...) with call to Configure<RouteOptions>…
mitchdenny 029b2dc
Make sure WebHost.CreateDefaultBuilder(...) configures RegexInlineRou…
mitchdenny 4b7991d
Fix using constraint build error.
mitchdenny dc6c143
Update src/Http/Routing/src/Constraints/RegexErrorStubRouteConstraint.cs
mitchdenny ae15aec
Update src/Http/Routing/test/UnitTests/RoutingServiceCollectionExtens…
mitchdenny d24a958
Update src/Http/Routing/src/RouteOptions.cs
mitchdenny e0ca212
Update src/DefaultBuilder/src/WebApplicationBuilder.cs
mitchdenny aa74554
Updates from PR feedback.
mitchdenny 94dcdef
Revert back to calling AddRouting(...) from WebHost for now.
mitchdenny f2cf03e
Change back to IConfigureOptions.
mitchdenny 8819aae
We did it!
mitchdenny b9e4f5a
Forogt to actually call configureRouting(...) :)
mitchdenny 5254b6f
Update src/DefaultBuilder/src/WebHost.cs
mitchdenny 9adca9c
Update src/DefaultBuilder/src/WebHost.cs
mitchdenny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Http/Routing/src/Constraints/RegexErrorStubRouteConstraint.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Routing.Constraints; | ||
|
||
internal sealed class RegexErrorStubRouteConstraint : IRouteConstraint | ||
{ | ||
public RegexErrorStubRouteConstraint(string _) | ||
{ | ||
throw new InvalidOperationException(Resources.RegexRouteContraint_NotConfigured); | ||
} | ||
|
||
bool IRouteConstraint.Match(HttpContext? httpContext, IRouter? route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) | ||
{ | ||
// Should never get called, but is same as throw in constructor in case constructor is changed. | ||
throw new InvalidOperationException(Resources.RegexRouteContraint_NotConfigured); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.Routing.RouteHandlerServices | ||
static Microsoft.AspNetCore.Routing.RouteHandlerServices.Map(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder! endpoints, string! pattern, System.Delegate! handler, System.Collections.Generic.IEnumerable<string!>! httpMethods, System.Func<System.Reflection.MethodInfo!, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions?, Microsoft.AspNetCore.Http.RequestDelegateMetadataResult!>! populateMetadata, System.Func<System.Delegate!, Microsoft.AspNetCore.Http.RequestDelegateFactoryOptions!, Microsoft.AspNetCore.Http.RequestDelegateMetadataResult?, Microsoft.AspNetCore.Http.RequestDelegateResult!>! createRequestDelegate) -> Microsoft.AspNetCore.Builder.RouteHandlerBuilder! | ||
static Microsoft.Extensions.DependencyInjection.RoutingServiceCollectionExtensions.AddRoutingCore(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Routing.Constraints; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection; | ||
|
||
internal sealed class RegexInlineRouteConstraintSetup : IConfigureOptions<RouteOptions> | ||
{ | ||
public void Configure(RouteOptions options) | ||
{ | ||
var existingRegexConstraintType = options.TrimmerSafeConstraintMap["regex"]; | ||
|
||
// Don't override regex constraint if it has already been overridden | ||
// this behavior here is just to add it back in if someone calls AddRouting(...) | ||
// after setting up routing with AddRoutingCore(...). | ||
if (existingRegexConstraintType == typeof(RegexErrorStubRouteConstraint)) | ||
{ | ||
options.SetParameterPolicy<RegexInlineRouteConstraint>("regex"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.