forked from dotnet/yarp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteConfig.cs
More file actions
144 lines (126 loc) · 6.25 KB
/
RouteConfig.cs
File metadata and controls
144 lines (126 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Yarp.ReverseProxy.Utilities;
namespace Yarp.ReverseProxy.Configuration;
/// <summary>
/// Describes a route that matches incoming requests based on the <see cref="Match"/> criteria
/// and proxies matching requests to the cluster identified by its <see cref="ClusterId"/>.
/// </summary>
public sealed record RouteConfig
{
/// <summary>
/// Globally unique identifier of the route.
/// This field is required.
/// </summary>
public string RouteId { get; init; } = default!;
/// <summary>
/// Parameters used to match requests.
/// This field is required.
/// </summary>
public RouteMatch Match { get; init; } = default!;
/// <summary>
/// Optionally, an order value for this route. Routes with lower numbers take precedence over higher numbers.
/// </summary>
public int? Order { get; init; }
/// <summary>
/// Gets or sets the cluster that requests matching this route
/// should be proxied to.
/// </summary>
public string? ClusterId { get; init; }
/// <summary>
/// The name of the AuthorizationPolicy to apply to this route.
/// If not set then only the FallbackPolicy will apply.
/// Set to "Default" to enable authorization with the applications default policy.
/// Set to "Anonymous" to disable all authorization checks for this route.
/// </summary>
public string? AuthorizationPolicy { get; init; }
/// <summary>
/// The name of the RateLimiterPolicy to apply to this route.
/// If not set then only the GlobalLimiter will apply.
/// Set to "Disable" to disable rate limiting for this route.
/// Set to "Default" or leave empty to use the global rate limits, if any.
/// </summary>
public string? RateLimiterPolicy { get; init; }
/// <summary>
/// The name of the OutputCachePolicy to apply to this route.
/// If not set then only the BasePolicy will apply.
/// </summary>
public string? OutputCachePolicy { get; init; }
/// <summary>
/// The name of the TimeoutPolicy to apply to this route.
/// Setting both Timeout and TimeoutPolicy is an error.
/// If not set then only the system default will apply.
/// Set to "Disable" to disable timeouts for this route.
/// Set to "Default" or leave empty to use the system defaults, if any.
/// </summary>
public string? TimeoutPolicy { get; init; }
/// <summary>
/// The Timeout to apply to this route. This overrides any system defaults.
/// Setting both Timeout and TimeoutPolicy is an error.
/// Timeout granularity is limited to milliseconds.
/// </summary>
public TimeSpan? Timeout { get; init; }
/// <summary>
/// The name of the CorsPolicy to apply to this route.
/// If not set then the route won't be automatically matched for cors preflight requests.
/// Set to "Default" to enable cors with the default policy.
/// Set to "Disable" to refuses cors requests for this route.
/// </summary>
public string? CorsPolicy { get; init; }
/// <summary>
/// An optional override for how large request bodies can be in bytes. If set, this overrides the server's default (30MB) per request.
/// Set to '-1' to disable the limit for this route.
/// Note that this limit applies only to the YARP forwarder middleware, it does not apply when reading the request body from a custom middleware registered via
/// <see cref="ReverseProxyIEndpointRouteBuilderExtensions.MapReverseProxy(IEndpointRouteBuilder, Action{IReverseProxyApplicationBuilder})"/>.
/// </summary>
public long? MaxRequestBodySize { get; init; }
/// <summary>
/// Arbitrary key-value pairs that further describe this route.
/// </summary>
public IReadOnlyDictionary<string, string>? Metadata { get; init; }
/// <summary>
/// Parameters used to transform the request and response. See <see cref="Transforms.Builder.ITransformBuilder"/>.
/// </summary>
public IReadOnlyList<IReadOnlyDictionary<string, string>>? Transforms { get; init; }
public bool Equals(RouteConfig? other)
{
if (other is null)
{
return false;
}
return Order == other.Order
&& string.Equals(RouteId, other.RouteId, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ClusterId, other.ClusterId, StringComparison.OrdinalIgnoreCase)
&& string.Equals(AuthorizationPolicy, other.AuthorizationPolicy, StringComparison.OrdinalIgnoreCase)
&& string.Equals(RateLimiterPolicy, other.RateLimiterPolicy, StringComparison.OrdinalIgnoreCase)
&& string.Equals(OutputCachePolicy, other.OutputCachePolicy, StringComparison.OrdinalIgnoreCase)
&& string.Equals(TimeoutPolicy, other.TimeoutPolicy, StringComparison.OrdinalIgnoreCase)
&& Timeout == other.Timeout
&& string.Equals(CorsPolicy, other.CorsPolicy, StringComparison.OrdinalIgnoreCase)
&& Match == other.Match
&& CaseSensitiveEqualHelper.Equals(Metadata, other.Metadata)
&& CaseSensitiveEqualHelper.Equals(Transforms, other.Transforms);
}
public override int GetHashCode()
{
// HashCode.Combine(...) takes only 8 arguments
var hash = new HashCode();
hash.Add(Order);
hash.Add(RouteId?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(ClusterId?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(AuthorizationPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(RateLimiterPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(OutputCachePolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(Timeout?.GetHashCode());
hash.Add(TimeoutPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(CorsPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(Match);
hash.Add(CaseSensitiveEqualHelper.GetHashCode(Metadata));
hash.Add(CaseSensitiveEqualHelper.GetHashCode(Transforms));
return hash.ToHashCode();
}
}