forked from dotnet/yarp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputCachePolicyValidator.cs
More file actions
45 lines (37 loc) · 1.43 KB
/
OutputCachePolicyValidator.cs
File metadata and controls
45 lines (37 loc) · 1.43 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
// 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 System.Threading.Tasks;
namespace Yarp.ReverseProxy.Configuration.RouteValidators;
internal sealed class OutputCachePolicyValidator : IRouteValidator
{
private readonly IYarpOutputCachePolicyProvider _outputCachePolicyProvider;
public OutputCachePolicyValidator(IYarpOutputCachePolicyProvider outputCachePolicyProvider)
{
_outputCachePolicyProvider = outputCachePolicyProvider;
}
public async ValueTask ValidateAsync(RouteConfig routeConfig, IList<Exception> errors)
{
var outputCachePolicyName = routeConfig.OutputCachePolicy;
if (string.IsNullOrEmpty(outputCachePolicyName))
{
return;
}
try
{
var policy = await _outputCachePolicyProvider.GetPolicyAsync(outputCachePolicyName);
if (policy is null)
{
errors.Add(new ArgumentException(
$"OutputCache policy '{outputCachePolicyName}' not found for route '{routeConfig.RouteId}'."));
}
}
catch (Exception ex)
{
errors.Add(new ArgumentException(
$"Unable to retrieve the OutputCache policy '{outputCachePolicyName}' for route '{routeConfig.RouteId}'.",
ex));
}
}
}