Skip to content

Commit c29db40

Browse files
authored
Add [StringSyntax("Route")] to route patterns (#2156)
1 parent 1bf9df3 commit c29db40

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

src/ReverseProxy/Routing/DirectForwardingIEndpointRouteBuilderExtensions.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Net.Http;
67
using Microsoft.AspNetCore.Routing;
78
using Microsoft.Extensions.DependencyInjection;
@@ -19,39 +20,59 @@ public static class DirectForwardingIEndpointRouteBuilderExtensions
1920
/// <summary>
2021
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using default configuration for the outgoing request, default transforms, and default HTTP client.
2122
/// </summary>
22-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix)
23+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
24+
#if NET7_0_OR_GREATER
25+
[StringSyntax("Route")]
26+
#endif
27+
string pattern, string destinationPrefix)
2328
{
2429
return endpoints.MapForwarder(pattern, destinationPrefix, ForwarderRequestConfig.Empty);
2530
}
2631

2732
/// <summary>
2833
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination and target path applying route values from the pattern using default configuration for the outgoing request, and default HTTP client.
2934
/// </summary>
30-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, string targetPath)
35+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
36+
#if NET7_0_OR_GREATER
37+
[StringSyntax("Route")]
38+
#endif
39+
string pattern, string destinationPrefix, string targetPath)
3140
{
3241
return endpoints.MapForwarder(pattern, destinationPrefix, ForwarderRequestConfig.Empty, targetPath);
3342
}
3443

3544
/// <summary>
3645
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination and target path applying route values from the pattern using customized configuration for the outgoing request, and default HTTP client.
3746
/// </summary>
38-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, string targetPath)
47+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
48+
#if NET7_0_OR_GREATER
49+
[StringSyntax("Route")]
50+
#endif
51+
string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, string targetPath)
3952
{
4053
return endpoints.MapForwarder(pattern, destinationPrefix, requestConfig, b => b.AddPathRouteValues(targetPath));
4154
}
4255

4356
/// <summary>
4457
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using default configuration for the outgoing request, customized transforms, and default HTTP client.
4558
/// </summary>
46-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, Action<TransformBuilderContext> configureTransform)
59+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
60+
#if NET7_0_OR_GREATER
61+
[StringSyntax("Route")]
62+
#endif
63+
string pattern, string destinationPrefix, Action<TransformBuilderContext> configureTransform)
4764
{
4865
return endpoints.MapForwarder(pattern, destinationPrefix, ForwarderRequestConfig.Empty, configureTransform);
4966
}
5067

5168
/// <summary>
5269
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using customized configuration for the outgoing request, customized transforms, and default HTTP client.
5370
/// </summary>
54-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, Action<TransformBuilderContext> configureTransform)
71+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
72+
#if NET7_0_OR_GREATER
73+
[StringSyntax("Route")]
74+
#endif
75+
string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, Action<TransformBuilderContext> configureTransform)
5576
{
5677
var transformBuilder = endpoints.ServiceProvider.GetRequiredService<ITransformBuilder>();
5778

@@ -63,15 +84,23 @@ public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder
6384
/// <summary>
6485
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using customized configuration for the outgoing request, default transforms, and default HTTP client.
6586
/// </summary>
66-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig)
87+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
88+
#if NET7_0_OR_GREATER
89+
[StringSyntax("Route")]
90+
#endif
91+
string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig)
6792
{
6893
return endpoints.MapForwarder(pattern, destinationPrefix, requestConfig, HttpTransformer.Default);
6994
}
7095

7196
/// <summary>
7297
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using customized configuration for the outgoing request, customized transforms, and default HTTP client.
7398
/// </summary>
74-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, HttpTransformer transformer)
99+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
100+
#if NET7_0_OR_GREATER
101+
[StringSyntax("Route")]
102+
#endif
103+
string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, HttpTransformer transformer)
75104
{
76105
var httpClientProvider = endpoints.ServiceProvider.GetRequiredService<DirectForwardingHttpClientProvider>();
77106

@@ -81,7 +110,11 @@ public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder
81110
/// <summary>
82111
/// Adds direct forwarding of HTTP requests that match the specified pattern to a specific destination using customized configuration for the outgoing request, customized transforms, and customized HTTP client.
83112
/// </summary>
84-
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints, string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, HttpTransformer transformer, HttpMessageInvoker httpClient)
113+
public static IEndpointConventionBuilder MapForwarder(this IEndpointRouteBuilder endpoints,
114+
#if NET7_0_OR_GREATER
115+
[StringSyntax("Route")]
116+
#endif
117+
string pattern, string destinationPrefix, ForwarderRequestConfig requestConfig, HttpTransformer transformer, HttpMessageInvoker httpClient)
85118
{
86119
ArgumentNullException.ThrowIfNull(endpoints);
87120
ArgumentNullException.ThrowIfNull(destinationPrefix);

src/ReverseProxy/Transforms/PathRouteValuesTransform.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Threading.Tasks;
67
using Microsoft.AspNetCore.Routing;
78
using Microsoft.AspNetCore.Routing.Patterns;
@@ -21,7 +22,11 @@ public class PathRouteValuesTransform : RequestTransform
2122
/// </summary>
2223
/// <param name="pattern">The pattern used to create the new request path.</param>
2324
/// <param name="binderFactory">The factory used to bind route parameters to the given path pattern.</param>
24-
public PathRouteValuesTransform(string pattern, TemplateBinderFactory binderFactory)
25+
public PathRouteValuesTransform(
26+
#if NET7_0_OR_GREATER
27+
[StringSyntax("Route")]
28+
#endif
29+
string pattern, TemplateBinderFactory binderFactory)
2530
{
2631
_ = pattern ?? throw new ArgumentNullException(nameof(pattern));
2732
_binderFactory = binderFactory ?? throw new ArgumentNullException(nameof(binderFactory));

0 commit comments

Comments
 (0)