Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions TFMs.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<LatestDevTFM>net9.0</LatestDevTFM>
<ReleaseTFMs>net6.0;net7.0;net8.0</ReleaseTFMs>
<TestTFMs>net6.0;net7.0;net8.0;net9.0</TestTFMs>
<ReleaseTFMs>net8.0</ReleaseTFMs>
<TestTFMs>net8.0;net9.0</TestTFMs>
</PropertyGroup>
</Project>
2 changes: 0 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
</PropertyGroup>
<!--Package versions-->
<PropertyGroup>
<SystemCollectionsImmutableVersion>8.0.0</SystemCollectionsImmutableVersion>
<SystemIOHashingVersion>8.0.0</SystemIOHashingVersion>
<MicrosoftBclTimeProviderVersion>8.0.0</MicrosoftBclTimeProviderVersion>
<MicrosoftAspNetCoreTestHostVersion>6.0.36</MicrosoftAspNetCoreTestHostVersion>
<MicrosoftCrankEventSourcesVersion>0.2.0-alpha.24576.2</MicrosoftCrankEventSourcesVersion>
<MicrosoftDotNetXUnitExtensionsPackageVersion>10.0.0-beta.25126.4</MicrosoftDotNetXUnitExtensionsPackageVersion>
Expand Down
4 changes: 0 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
"dotnet": "10.0.100-preview.3.25125.5",
"runtimes": {
"dotnet": [
"6.0.36",
"7.0.20",
"8.0.13",
"9.0.2"
],
"aspnetcore": [
"6.0.36",
"7.0.20",
"8.0.13",
"9.0.2"
]
Expand Down
4 changes: 2 additions & 2 deletions samples/BasicYarpSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ This sample reads its configuration from the [appsettings.json](appsettings.json

**Note:** The destination addresses used in the sample are using DNS names rather than IP addresses, this is so that the sample can be run and used without further changes. In a typical deployment, the destination servers should be specified with protocol, IP & ports, such as "https://123.4.5.6:7890"

The proxy will listen to HTTP requests on port 5000, and HTTPS on port 5001. These are changable via the URLs property in config, and can be limited to just one protocol if required.
The proxy will listen to HTTP requests on port 5000, and HTTPS on port 5001. These are changeable via the URLs property in config, and can be limited to just one protocol if required.

## Files
- [BasicYarpSample.csproj](BasicYarpSample.csproj) - A C# project file (conceptually similar to a make file) that tells it to target the .NET 6 runtime, and to reference the proxy library from [nuget](https://www.nuget.org/packages/Yarp.ReverseProxy/) (.NET's package manager).
- [BasicYarpSample.csproj](BasicYarpSample.csproj) - A C# project file (conceptually similar to a make file) that tells it to target the .NET 8 runtime, and to reference the proxy library from [nuget](https://www.nuget.org/packages/Yarp.ReverseProxy/) (.NET's package manager).
- [Program.cs](Program.cs) - Provides the main entrypoint for .NET which uses a WebApplication to initialize the server which listens for http requests. This is also used to configure and control how http requests are handled by the server. In this sample, it does the bare minimum of:
- Adding proxy functionality to the services collection.
- Specifying that the proxy configuration will come from the config file (alternatively it could be specified via code).
Expand Down
2 changes: 0 additions & 2 deletions samples/KubernetesIngress.Sample/Combined/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// 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.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down
3 changes: 0 additions & 3 deletions samples/KubernetesIngress.Sample/Ingress/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// 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.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down
1 change: 0 additions & 1 deletion samples/ReverseProxy.Auth.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Yarp.ReverseProxy.Transforms;
using Yarp.Sample;
Expand Down
1 change: 0 additions & 1 deletion src/Application/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

// Load configuration
if (args.Length != 1)
Expand Down
2 changes: 0 additions & 2 deletions src/Kubernetes.Controller/Converters/YarpIngressOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ internal sealed class YarpIngressOptions
public bool Https { get; set; }
public List<Dictionary<string, string>> Transforms { get; set; }
public string AuthorizationPolicy { get; set; }
#if NET7_0_OR_GREATER
public string RateLimiterPolicy { get; set; }
public string OutputCachePolicy { get; set; }
#endif
public SessionAffinityConfig SessionAffinity { get; set; }
public HttpClientConfig HttpClientConfig { get; set; }
public string LoadBalancingPolicy { get; set; }
Expand Down
8 changes: 0 additions & 8 deletions src/Kubernetes.Controller/Converters/YarpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,10 @@ private static RouteConfig CreateRoute(YarpIngressContext ingressContext, V1HTTP
RouteId = $"{ingressContext.Ingress.Metadata.Name}.{ingressContext.Ingress.Metadata.NamespaceProperty}:{host}{path.Path}",
Transforms = ingressContext.Options.Transforms,
AuthorizationPolicy = ingressContext.Options.AuthorizationPolicy,
#if NET7_0_OR_GREATER
RateLimiterPolicy = ingressContext.Options.RateLimiterPolicy,
OutputCachePolicy = ingressContext.Options.OutputCachePolicy,
#endif
#if NET8_0_OR_GREATER
Timeout = ingressContext.Options.Timeout,
TimeoutPolicy = ingressContext.Options.TimeoutPolicy,
#endif
CorsPolicy = ingressContext.Options.CorsPolicy,
Metadata = ingressContext.Options.RouteMetadata,
Order = ingressContext.Options.RouteOrder,
Expand Down Expand Up @@ -232,7 +228,6 @@ private static YarpIngressOptions HandleAnnotations(YarpIngressContext context,
{
options.AuthorizationPolicy = authorizationPolicy;
}
#if NET7_0_OR_GREATER
if (annotations.TryGetValue("yarp.ingress.kubernetes.io/rate-limiter-policy", out var rateLimiterPolicy))
{
options.RateLimiterPolicy = rateLimiterPolicy;
Expand All @@ -241,8 +236,6 @@ private static YarpIngressOptions HandleAnnotations(YarpIngressContext context,
{
options.OutputCachePolicy = outputCachePolicy;
}
#endif
#if NET8_0_OR_GREATER
if (annotations.TryGetValue("yarp.ingress.kubernetes.io/timeout", out var timeout))
{
options.Timeout = TimeSpan.Parse(timeout, CultureInfo.InvariantCulture);
Expand All @@ -251,7 +244,6 @@ private static YarpIngressOptions HandleAnnotations(YarpIngressContext context,
{
options.TimeoutPolicy = timeoutPolicy;
}
#endif
if (annotations.TryGetValue("yarp.ingress.kubernetes.io/cors-policy", out var corsPolicy))
{
options.CorsPolicy = corsPolicy;
Expand Down
7 changes: 0 additions & 7 deletions src/Kubernetes.Controller/Protocol/Receiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
Expand All @@ -15,7 +13,6 @@
using Yarp.Kubernetes.Controller.Configuration;
using Yarp.Kubernetes.Controller.Hosting;
using Yarp.Kubernetes.Controller.Rate;
using Yarp.ReverseProxy.Forwarder;

namespace Yarp.Kubernetes.Protocol;

Expand Down Expand Up @@ -65,11 +62,7 @@ public override async Task RunAsync(CancellationToken cancellationToken)
using var cancellation = cancellationToken.Register(stream.Close);
while (true)
{
#if NET6_0
var json = await reader.ReadLineAsync().ConfigureAwait(false);
#else
var json = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
#endif
if (string.IsNullOrEmpty(json))
{
break;
Expand Down
1 change: 0 additions & 1 deletion src/Kubernetes.Controller/Rate/Limiter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Internal;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down
1 change: 0 additions & 1 deletion src/Kubernetes.Controller/Rate/Reservation.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Internal;
using System;

#pragma warning disable CS0169 // The field 'Reservation.limit' is never used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,10 @@ private static RouteConfig CreateRoute(IConfigurationSection section)
MaxRequestBodySize = section.ReadInt64(nameof(RouteConfig.MaxRequestBodySize)),
ClusterId = section[nameof(RouteConfig.ClusterId)],
AuthorizationPolicy = section[nameof(RouteConfig.AuthorizationPolicy)],
#if NET7_0_OR_GREATER
RateLimiterPolicy = section[nameof(RouteConfig.RateLimiterPolicy)],
OutputCachePolicy = section[nameof(RouteConfig.OutputCachePolicy)],
#endif
#if NET8_0_OR_GREATER
TimeoutPolicy = section[nameof(RouteConfig.TimeoutPolicy)],
Timeout = section.ReadTimeSpan(nameof(RouteConfig.Timeout)),
#endif
CorsPolicy = section[nameof(RouteConfig.CorsPolicy)],
Metadata = section.GetSection(nameof(RouteConfig.Metadata)).ReadStringDictionary(),
Transforms = CreateTransforms(section.GetSection(nameof(RouteConfig.Transforms))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET7_0_OR_GREATER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.OutputCaching;
using Microsoft.Extensions.Options;
#endif

using System.Collections.Generic;
using System.Threading.Tasks;

namespace Yarp.ReverseProxy.Configuration;

Expand All @@ -24,7 +21,6 @@ internal interface IYarpOutputCachePolicyProvider

internal sealed class YarpOutputCachePolicyProvider : IYarpOutputCachePolicyProvider
{
#if NET7_0_OR_GREATER
// Workaround for https://github.com/dotnet/yarp/issues/2598 to make YARP work with NativeAOT on .NET 8. This is not needed on .NET 9+.
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private static readonly Type s_OutputCacheOptionsType = typeof(OutputCacheOptions);
Expand All @@ -49,10 +45,4 @@ public YarpOutputCachePolicyProvider(IOptions<OutputCacheOptions> outputCacheOpt
{
return ValueTask.FromResult(_policyMap[policyName]);
}
#else
public ValueTask<object?> GetPolicyAsync(string policyName)
{
return default;
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET7_0_OR_GREATER
using System;
using System.Collections;
using System.Reflection;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.Extensions.Options;
#endif

using System.Threading.Tasks;

namespace Yarp.ReverseProxy.Configuration;

// TODO: update or remove this once AspNetCore provides a mechanism to validate the RateLimiter policies https://github.com/dotnet/aspnetcore/issues/45684


internal interface IYarpRateLimiterPolicyProvider
{
ValueTask<object?> GetPolicyAsync(string policyName);
}

internal sealed class YarpRateLimiterPolicyProvider : IYarpRateLimiterPolicyProvider
{
#if NET7_0_OR_GREATER
private readonly RateLimiterOptions _rateLimiterOptions;

private readonly IDictionary _policyMap, _unactivatedPolicyMap;
Expand All @@ -44,10 +40,4 @@ public YarpRateLimiterPolicyProvider(IOptions<RateLimiterOptions> rateLimiterOpt
{
return ValueTask.FromResult(_policyMap[policyName] ?? _unactivatedPolicyMap[policyName]);
}
#else
public ValueTask<object?> GetPolicyAsync(string policyName)
{
return default;
}
#endif
}
15 changes: 3 additions & 12 deletions src/ReverseProxy/Configuration/RouteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public sealed record RouteConfig
/// Set to "Anonymous" to disable all authorization checks for this route.
/// </summary>
public string? AuthorizationPolicy { get; init; }
#if NET7_0_OR_GREATER

/// <summary>
/// The name of the RateLimiterPolicy to apply to this route.
/// If not set then only the GlobalLimiter will apply.
Expand All @@ -59,8 +59,7 @@ public sealed record RouteConfig
/// If not set then only the BasePolicy will apply.
/// </summary>
public string? OutputCachePolicy { get; init; }
#endif
#if NET8_0_OR_GREATER

/// <summary>
/// The name of the TimeoutPolicy to apply to this route.
/// Setting both Timeout and TimeoutPolicy is an error.
Expand All @@ -76,7 +75,7 @@ public sealed record RouteConfig
/// Timeout granularity is limited to milliseconds.
/// </summary>
public TimeSpan? Timeout { get; init; }
#endif

/// <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.
Expand Down Expand Up @@ -114,14 +113,10 @@ public bool Equals(RouteConfig? other)
&& string.Equals(RouteId, other.RouteId, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ClusterId, other.ClusterId, StringComparison.OrdinalIgnoreCase)
&& string.Equals(AuthorizationPolicy, other.AuthorizationPolicy, StringComparison.OrdinalIgnoreCase)
#if NET7_0_OR_GREATER
&& string.Equals(RateLimiterPolicy, other.RateLimiterPolicy, StringComparison.OrdinalIgnoreCase)
&& string.Equals(OutputCachePolicy, other.OutputCachePolicy, StringComparison.OrdinalIgnoreCase)
#endif
#if NET8_0_OR_GREATER
&& string.Equals(TimeoutPolicy, other.TimeoutPolicy, StringComparison.OrdinalIgnoreCase)
&& Timeout == other.Timeout
#endif
&& string.Equals(CorsPolicy, other.CorsPolicy, StringComparison.OrdinalIgnoreCase)
&& Match == other.Match
&& CaseSensitiveEqualHelper.Equals(Metadata, other.Metadata)
Expand All @@ -136,14 +131,10 @@ public override int GetHashCode()
hash.Add(RouteId?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(ClusterId?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(AuthorizationPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
#if NET7_0_OR_GREATER
hash.Add(RateLimiterPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(OutputCachePolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
#endif
#if NET8_0_OR_GREATER
hash.Add(Timeout?.GetHashCode());
hash.Add(TimeoutPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
#endif
hash.Add(CorsPolicy?.GetHashCode(StringComparison.OrdinalIgnoreCase));
hash.Add(Match);
hash.Add(CaseSensitiveEqualHelper.GetHashCode(Metadata));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Yarp.ReverseProxy.Configuration.RouteValidators;

internal sealed class OutputCachePolicyValidator : IRouteValidator
{
#if NET7_0_OR_GREATER
private readonly IYarpOutputCachePolicyProvider _outputCachePolicyProvider;

public OutputCachePolicyValidator(IYarpOutputCachePolicyProvider outputCachePolicyProvider)
{
_outputCachePolicyProvider = outputCachePolicyProvider;
Expand Down Expand Up @@ -42,7 +42,4 @@ public async ValueTask ValidateAsync(RouteConfig routeConfig, IList<Exception> e
ex));
}
}
#else
public ValueTask ValidateAsync(RouteConfig routeConfig, IList<Exception> errors) => ValueTask.CompletedTask;
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Yarp.ReverseProxy.Configuration.RouteValidators;

internal sealed class RateLimitPolicyValidator : IRouteValidator
{
#if NET7_0_OR_GREATER
private readonly IYarpRateLimiterPolicyProvider _rateLimiterPolicyProvider;

public RateLimitPolicyValidator(IYarpRateLimiterPolicyProvider rateLimiterPolicyProvider)
{
_rateLimiterPolicyProvider = rateLimiterPolicyProvider;
Expand Down Expand Up @@ -56,7 +56,4 @@ public async ValueTask ValidateAsync(RouteConfig routeConfig, IList<Exception> e
ex));
}
}
#else
public ValueTask ValidateAsync(RouteConfig routeConfig, IList<Exception> errors) => ValueTask.CompletedTask;
#endif
}
Loading
Loading