diff --git a/Directory.Build.props b/Directory.Build.props
index dbb167c88..bf2077319 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -12,7 +12,6 @@
Microsoft
true
true
- false
diff --git a/TFMs.props b/TFMs.props
index 42da1007c..e582b1e02 100644
--- a/TFMs.props
+++ b/TFMs.props
@@ -2,7 +2,7 @@
net9.0
- net6.0;net7.0;net8.0
- net6.0;net7.0;net8.0;net9.0
+ net8.0
+ net8.0;net9.0
diff --git a/eng/Versions.props b/eng/Versions.props
index fa7532a79..75c2d881c 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -12,9 +12,7 @@
- 8.0.0
8.0.0
- 8.0.0
6.0.36
0.2.0-alpha.24576.2
10.0.0-beta.25126.4
diff --git a/global.json b/global.json
index 0722cc362..d1b61529e 100644
--- a/global.json
+++ b/global.json
@@ -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"
]
diff --git a/samples/BasicYarpSample/README.md b/samples/BasicYarpSample/README.md
index f75ba03e0..5dee4eefb 100644
--- a/samples/BasicYarpSample/README.md
+++ b/samples/BasicYarpSample/README.md
@@ -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).
diff --git a/samples/KubernetesIngress.Sample/Combined/Program.cs b/samples/KubernetesIngress.Sample/Combined/Program.cs
index 599ba5f32..016267bf0 100644
--- a/samples/KubernetesIngress.Sample/Combined/Program.cs
+++ b/samples/KubernetesIngress.Sample/Combined/Program.cs
@@ -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;
diff --git a/samples/KubernetesIngress.Sample/Ingress/Program.cs b/samples/KubernetesIngress.Sample/Ingress/Program.cs
index 2fe19c0be..f546b4a8c 100644
--- a/samples/KubernetesIngress.Sample/Ingress/Program.cs
+++ b/samples/KubernetesIngress.Sample/Ingress/Program.cs
@@ -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;
diff --git a/samples/ReverseProxy.Auth.Sample/Program.cs b/samples/ReverseProxy.Auth.Sample/Program.cs
index 16e5b66cc..3da486c8f 100644
--- a/samples/ReverseProxy.Auth.Sample/Program.cs
+++ b/samples/ReverseProxy.Auth.Sample/Program.cs
@@ -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;
diff --git a/src/Application/Program.cs b/src/Application/Program.cs
index 1a33a51a9..bfbc7aeb1 100644
--- a/src/Application/Program.cs
+++ b/src/Application/Program.cs
@@ -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)
diff --git a/src/Kubernetes.Controller/Converters/YarpIngressOptions.cs b/src/Kubernetes.Controller/Converters/YarpIngressOptions.cs
index f4481e4f1..4bf50a0c3 100644
--- a/src/Kubernetes.Controller/Converters/YarpIngressOptions.cs
+++ b/src/Kubernetes.Controller/Converters/YarpIngressOptions.cs
@@ -12,10 +12,8 @@ internal sealed class YarpIngressOptions
public bool Https { get; set; }
public List> 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; }
diff --git a/src/Kubernetes.Controller/Converters/YarpParser.cs b/src/Kubernetes.Controller/Converters/YarpParser.cs
index 6efcd2882..6a1156642 100644
--- a/src/Kubernetes.Controller/Converters/YarpParser.cs
+++ b/src/Kubernetes.Controller/Converters/YarpParser.cs
@@ -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,
@@ -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;
@@ -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);
@@ -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;
diff --git a/src/Kubernetes.Controller/Protocol/Receiver.cs b/src/Kubernetes.Controller/Protocol/Receiver.cs
index ee74bc9b0..1b1af04e7 100644
--- a/src/Kubernetes.Controller/Protocol/Receiver.cs
+++ b/src/Kubernetes.Controller/Protocol/Receiver.cs
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/Kubernetes.Controller/Rate/Limiter.cs b/src/Kubernetes.Controller/Rate/Limiter.cs
index 0eeabb0b3..1d905bedd 100644
--- a/src/Kubernetes.Controller/Rate/Limiter.cs
+++ b/src/Kubernetes.Controller/Rate/Limiter.cs
@@ -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;
diff --git a/src/Kubernetes.Controller/Rate/Reservation.cs b/src/Kubernetes.Controller/Rate/Reservation.cs
index c9e5711a3..5677df567 100644
--- a/src/Kubernetes.Controller/Rate/Reservation.cs
+++ b/src/Kubernetes.Controller/Rate/Reservation.cs
@@ -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
diff --git a/src/ReverseProxy/Configuration/ConfigProvider/ConfigurationConfigProvider.cs b/src/ReverseProxy/Configuration/ConfigProvider/ConfigurationConfigProvider.cs
index e9a49c928..a3c6c7dee 100644
--- a/src/ReverseProxy/Configuration/ConfigProvider/ConfigurationConfigProvider.cs
+++ b/src/ReverseProxy/Configuration/ConfigProvider/ConfigurationConfigProvider.cs
@@ -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))),
diff --git a/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs b/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs
index fb6009bbd..def89df61 100644
--- a/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs
+++ b/src/ReverseProxy/Configuration/IYarpOutputCachePolicyProvider.cs
@@ -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;
@@ -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);
@@ -49,10 +45,4 @@ public YarpOutputCachePolicyProvider(IOptions outputCacheOpt
{
return ValueTask.FromResult(_policyMap[policyName]);
}
-#else
- public ValueTask
-
-
diff --git a/src/TelemetryConsumption/Http/HttpEventListenerService.cs b/src/TelemetryConsumption/Http/HttpEventListenerService.cs
index 773ea55fd..c6208e1ec 100644
--- a/src/TelemetryConsumption/Http/HttpEventListenerService.cs
+++ b/src/TelemetryConsumption/Http/HttpEventListenerService.cs
@@ -15,11 +15,7 @@ internal sealed class HttpEventListenerService : EventListenerService "System.Net.Http";
-#if NET8_0_OR_GREATER
protected override int NumberOfMetrics => 11;
-#else
- protected override int NumberOfMetrics => 9;
-#endif
public HttpEventListenerService(ILogger logger, IEnumerable telemetryConsumers, IEnumerable> metricsConsumers)
: base(logger, telemetryConsumers, metricsConsumers)
@@ -54,36 +50,22 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
case 2:
Debug.Assert(eventData.EventName == "RequestStop" && payload.Count == (eventData.Version == 0 ? 0 : 1));
{
-#if NET8_0_OR_GREATER
var statusCode = (int)payload[0];
foreach (var consumer in consumers)
{
consumer.OnRequestStop(eventData.TimeStamp, statusCode);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnRequestStop(eventData.TimeStamp);
- }
-#endif
}
break;
case 3:
Debug.Assert(eventData.EventName == "RequestFailed" && payload.Count == (eventData.Version == 0 ? 0 : 1));
{
-#if NET8_0_OR_GREATER
var exceptionMessage = (string)payload[0];
foreach (var consumer in consumers)
{
consumer.OnRequestFailed(eventData.TimeStamp, exceptionMessage);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnRequestFailed(eventData.TimeStamp);
- }
-#endif
}
break;
@@ -92,7 +74,6 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
{
var versionMajor = (int)(byte)payload[0];
var versionMinor = (int)(byte)payload[1];
-#if NET8_0_OR_GREATER
var connectionId = (long)payload[2];
var scheme = (string)payload[3];
var host = (string)payload[4];
@@ -102,12 +83,6 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
{
consumer.OnConnectionEstablished(eventData.TimeStamp, versionMajor, versionMinor, connectionId, scheme, host, port, remoteAddress);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnConnectionEstablished(eventData.TimeStamp, versionMajor, versionMinor);
- }
-#endif
}
break;
@@ -116,18 +91,11 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
{
var versionMajor = (int)(byte)payload[0];
var versionMinor = (int)(byte)payload[1];
-#if NET8_0_OR_GREATER
var connectionId = (long)payload[2];
foreach (var consumer in consumers)
{
consumer.OnConnectionClosed(eventData.TimeStamp, versionMajor, versionMinor, connectionId);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnConnectionClosed(eventData.TimeStamp, versionMajor, versionMinor);
- }
-#endif
}
break;
@@ -147,18 +115,11 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
case 7:
Debug.Assert(eventData.EventName == "RequestHeadersStart" && payload.Count == (eventData.Version == 0 ? 0 : 1));
{
-#if NET8_0_OR_GREATER
var connectionId = (long)payload[0];
foreach (var consumer in consumers)
{
consumer.OnRequestHeadersStart(eventData.TimeStamp, connectionId);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnRequestHeadersStart(eventData.TimeStamp);
- }
-#endif
}
break;
@@ -206,18 +167,11 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
case 12:
Debug.Assert(eventData.EventName == "ResponseHeadersStop" && payload.Count == (eventData.Version == 0 ? 0 : 1));
{
-#if NET8_0_OR_GREATER
var statusCode = (int)payload[0];
foreach (var consumer in consumers)
{
consumer.OnResponseHeadersStop(eventData.TimeStamp, statusCode);
}
-#else
- foreach (var consumer in consumers)
- {
- consumer.OnResponseHeadersStop(eventData.TimeStamp);
- }
-#endif
}
break;
@@ -249,7 +203,6 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
case 16:
Debug.Assert(eventData.EventName == "Redirect" && payload.Count == 1);
-#if NET8_0_OR_GREATER
{
var redirectUri = (string)payload[0];
foreach (var consumer in consumers)
@@ -257,7 +210,6 @@ protected override void OnEvent(IHttpTelemetryConsumer[] consumers, EventWritten
consumer.OnRedirect(eventData.TimeStamp, redirectUri);
}
}
-#endif
break;
}
}
@@ -302,7 +254,6 @@ protected override bool TrySaveMetric(HttpMetrics metrics, string name, double v
metrics.Http20RequestsQueueDuration = TimeSpan.FromMilliseconds(value);
break;
-#if NET8_0_OR_GREATER
case "http30-connections-current-total":
metrics.CurrentHttp30Connections = (long)value;
break;
@@ -310,7 +261,6 @@ protected override bool TrySaveMetric(HttpMetrics metrics, string name, double v
case "http30-requests-queue-duration":
metrics.Http30RequestsQueueDuration = TimeSpan.FromMilliseconds(value);
break;
-#endif
default:
return false;
diff --git a/src/TelemetryConsumption/Http/HttpMetrics.cs b/src/TelemetryConsumption/Http/HttpMetrics.cs
index cd886d7c5..73ef16091 100644
--- a/src/TelemetryConsumption/Http/HttpMetrics.cs
+++ b/src/TelemetryConsumption/Http/HttpMetrics.cs
@@ -62,7 +62,6 @@ public sealed class HttpMetrics
///
public TimeSpan Http20RequestsQueueDuration { get; internal set; }
-#if NET8_0_OR_GREATER
///
/// Number of currently open HTTP 3.0 connections.
///
@@ -72,5 +71,4 @@ public sealed class HttpMetrics
/// Average time spent on queue for HTTP 3.0 requests in the last metrics interval.
///
public TimeSpan Http30RequestsQueueDuration { get; internal set; }
-#endif
}
diff --git a/src/TelemetryConsumption/Http/IHttpTelemetryConsumer.cs b/src/TelemetryConsumption/Http/IHttpTelemetryConsumer.cs
index cc55dd2d3..0c2698370 100644
--- a/src/TelemetryConsumption/Http/IHttpTelemetryConsumer.cs
+++ b/src/TelemetryConsumption/Http/IHttpTelemetryConsumer.cs
@@ -112,9 +112,6 @@ void OnResponseContentStart(DateTime timestamp) { }
/// Timestamp when the event was fired.
void OnResponseContentStop(DateTime timestamp) { }
- // Some events were augmented in .NET 8 with more parameters.
- // For backwards compatibility, they are implemented as DIMs that forward to older methods with fewer parameters.
-#if NET8_0_OR_GREATER
///
/// Called after an HTTP request.
///
@@ -177,5 +174,4 @@ void OnResponseHeadersStop(DateTime timestamp, int statusCode) =>
/// Timestamp when the event was fired.
/// The uri the request is being redirected to.
void OnRedirect(DateTime timestamp, string redirectUri) { }
-#endif
}
diff --git a/src/TelemetryConsumption/Sockets/SocketsEventListenerService.cs b/src/TelemetryConsumption/Sockets/SocketsEventListenerService.cs
index 105766f1b..f72b2658c 100644
--- a/src/TelemetryConsumption/Sockets/SocketsEventListenerService.cs
+++ b/src/TelemetryConsumption/Sockets/SocketsEventListenerService.cs
@@ -14,11 +14,7 @@ internal sealed class SocketsEventListenerService : EventListenerService "System.Net.Sockets";
-#if NET8_0_OR_GREATER
protected override int NumberOfMetrics => 7;
-#else
- protected override int NumberOfMetrics => 6;
-#endif
public SocketsEventListenerService(ILogger logger, IEnumerable telemetryConsumers, IEnumerable> metricsConsumers)
: base(logger, telemetryConsumers, metricsConsumers)
@@ -98,11 +94,9 @@ protected override bool TrySaveMetric(SocketsMetrics metrics, string name, doubl
metrics.DatagramsSent = longValue;
break;
-#if NET8_0_OR_GREATER
case "current-outgoing-connect-attempts":
metrics.CurrentOutgoingConnectAttempts = longValue;
break;
-#endif
default:
return false;
diff --git a/src/TelemetryConsumption/Sockets/SocketsMetrics.cs b/src/TelemetryConsumption/Sockets/SocketsMetrics.cs
index 94f42d14d..8af820928 100644
--- a/src/TelemetryConsumption/Sockets/SocketsMetrics.cs
+++ b/src/TelemetryConsumption/Sockets/SocketsMetrics.cs
@@ -47,10 +47,8 @@ public sealed class SocketsMetrics
///
public long DatagramsSent { get; internal set; }
-#if NET8_0_OR_GREATER
///
/// Number of outgoing (Connect) Socket connection attempts that are currently in progress.
///
public long CurrentOutgoingConnectAttempts { get; internal set; }
-#endif
}
diff --git a/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj b/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj
index 2f642c021..44ba86311 100644
--- a/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj
+++ b/src/TelemetryConsumption/Yarp.Telemetry.Consumption.csproj
@@ -6,7 +6,7 @@
Library
Yarp.Telemetry.Consumption
enable
- true
+ true
README.md
yarp;dotnet;reverse-proxy;aspnetcore;telemetry
diff --git a/test/Kubernetes.Tests/IngressControllerTests.cs b/test/Kubernetes.Tests/IngressControllerTests.cs
index d18b43372..ff5406ee1 100644
--- a/test/Kubernetes.Tests/IngressControllerTests.cs
+++ b/test/Kubernetes.Tests/IngressControllerTests.cs
@@ -4,7 +4,6 @@
using k8s;
using k8s.Models;
using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using System;
diff --git a/test/Kubernetes.Tests/IngressConversionTests.cs b/test/Kubernetes.Tests/IngressConversionTests.cs
index 05d1c101a..70f474fac 100644
--- a/test/Kubernetes.Tests/IngressConversionTests.cs
+++ b/test/Kubernetes.Tests/IngressConversionTests.cs
@@ -85,12 +85,7 @@ private static void VerifyClusters(string clusterJson, string name)
private static void VerifyRoutes(string routesJson, string name)
{
-#if NET7_0_OR_GREATER
VerifyJson(routesJson, name, "routes.json");
-#else
- VerifyJson(routesJson, name,
- string.Equals("annotations", name, StringComparison.OrdinalIgnoreCase) ? "routes.net6.json" : "routes.json");
-#endif
}
private static string StripNullProperties(string json)
diff --git a/test/Kubernetes.Tests/KubeResourceGenerator.cs b/test/Kubernetes.Tests/KubeResourceGenerator.cs
index 6690d7577..2d6ad4a7c 100644
--- a/test/Kubernetes.Tests/KubeResourceGenerator.cs
+++ b/test/Kubernetes.Tests/KubeResourceGenerator.cs
@@ -1,10 +1,8 @@
// 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.Globalization;
-using System.Linq;
using k8s.Models;
namespace Yarp.Kubernetes.Tests;
diff --git a/test/Kubernetes.Tests/testassets/annotations/routes.net6.json b/test/Kubernetes.Tests/testassets/annotations/routes.net6.json
deleted file mode 100644
index dcb0e7e27..000000000
--- a/test/Kubernetes.Tests/testassets/annotations/routes.net6.json
+++ /dev/null
@@ -1,23 +0,0 @@
-[
- {
- "RouteId": "minimal-ingress.default:/foo",
- "Match": {
- "Methods": null,
- "Hosts": [],
- "Path": "/foo/{**catch-all}",
- "Headers": null
- },
- "Order": null,
- "ClusterId": "frontend.default:80",
- "AuthorizationPolicy": "authzpolicy",
- "CorsPolicy": "corspolicy",
- "Metadata": null,
- "Transforms": [
- { "PathPrefix": "/apis" },
- {
- "RequestHeader": "header1",
- "Append": "bar"
- }
- ]
- }
-]
diff --git a/test/ReverseProxy.FunctionalTests/Common/TestEnvironment.cs b/test/ReverseProxy.FunctionalTests/Common/TestEnvironment.cs
index 8febb6ee5..0831a46e4 100644
--- a/test/ReverseProxy.FunctionalTests/Common/TestEnvironment.cs
+++ b/test/ReverseProxy.FunctionalTests/Common/TestEnvironment.cs
@@ -10,8 +10,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Hosting.Server.Features;
-using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.HttpSys;
using Microsoft.AspNetCore.Server.Kestrel.Core;
diff --git a/test/ReverseProxy.FunctionalTests/Expect100ContinueTests.cs b/test/ReverseProxy.FunctionalTests/Expect100ContinueTests.cs
index 5d6aece50..338fdc9a2 100644
--- a/test/ReverseProxy.FunctionalTests/Expect100ContinueTests.cs
+++ b/test/ReverseProxy.FunctionalTests/Expect100ContinueTests.cs
@@ -9,7 +9,6 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Core;
-using Microsoft.DotNet.XUnitExtensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
@@ -187,8 +186,6 @@ await ProcessHttpRequest(new Uri(uri), proxyProtocol, contentString, useContentL
});
}
- // Fix was implemented in https://github.com/dotnet/runtime/pull/58548
-#if NET7_0_OR_GREATER
[ConditionalTheory(nameof(Http2OverTlsSupported))]
[InlineData(HttpProtocols.Http1, HttpProtocols.Http1, false)]
[InlineData(HttpProtocols.Http2, HttpProtocols.Http2, false)]
@@ -198,7 +195,7 @@ await ProcessHttpRequest(new Uri(uri), proxyProtocol, contentString, useContentL
[InlineData(HttpProtocols.Http2, HttpProtocols.Http2, true)]
[InlineData(HttpProtocols.Http1, HttpProtocols.Http2, true)]
[InlineData(HttpProtocols.Http2, HttpProtocols.Http1, true)]
- public async Task PostExpect100_SkipRequestBodyWithUnsuccesfulResponseCode(HttpProtocols proxyProtocol, HttpProtocols destProtocol, bool useContentLength)
+ public async Task PostExpect100_SkipRequestBodyWithUnsuccessfulResponseCode(HttpProtocols proxyProtocol, HttpProtocols destProtocol, bool useContentLength)
{
var requestBodyTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -248,7 +245,6 @@ await ProcessHttpRequest(new Uri(uri), proxyProtocol, contentString, useContentL
});
});
}
-#endif
private static async Task ReadContent(Microsoft.AspNetCore.Http.HttpContext context, TaskCompletionSource bodyTcs, int byteCount)
{
diff --git a/test/ReverseProxy.FunctionalTests/HeaderTests.cs b/test/ReverseProxy.FunctionalTests/HeaderTests.cs
index 5e26e215c..af21e8959 100644
--- a/test/ReverseProxy.FunctionalTests/HeaderTests.cs
+++ b/test/ReverseProxy.FunctionalTests/HeaderTests.cs
@@ -10,7 +10,6 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
@@ -426,15 +425,10 @@ public async Task ContentLengthAndTransferEncoding_ContentLengthRemoved()
{
try
{
-#if NET8_0_OR_GREATER
// Removed by the server
Assert.Null(context.Request.ContentLength);
// Set it just to make sure YARP removes it
context.Request.ContentLength = 11;
-#else
- // Fixed in 8.0 https://github.com/dotnet/aspnetcore/issues/43523
- Assert.Equal(11, context.Request.ContentLength);
-#endif
Assert.Equal("chunked", context.Request.Headers[HeaderNames.TransferEncoding]);
proxyTcs.SetResult(0);
}
diff --git a/test/ReverseProxy.FunctionalTests/HttpForwarderCancellationTests.cs b/test/ReverseProxy.FunctionalTests/HttpForwarderCancellationTests.cs
index 4fe87cc8a..333781664 100644
--- a/test/ReverseProxy.FunctionalTests/HttpForwarderCancellationTests.cs
+++ b/test/ReverseProxy.FunctionalTests/HttpForwarderCancellationTests.cs
@@ -10,7 +10,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features;
-using Microsoft.AspNetCore.Server.Kestrel.Core;
using Xunit;
using Yarp.ReverseProxy.Common;
using Yarp.ReverseProxy.Utilities;
diff --git a/test/ReverseProxy.FunctionalTests/HttpProxyCookieTests.cs b/test/ReverseProxy.FunctionalTests/HttpProxyCookieTests.cs
index 6a43ceceb..ecd7f82f7 100644
--- a/test/ReverseProxy.FunctionalTests/HttpProxyCookieTests.cs
+++ b/test/ReverseProxy.FunctionalTests/HttpProxyCookieTests.cs
@@ -4,7 +4,6 @@
using System;
using System.Net;
using System.Net.Http;
-using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
@@ -81,23 +80,11 @@ public async Task Invoke(HttpContext context)
// Ensure that CookieA is the first and CookieB the last.
Assert.True(context.Request.Headers.TryGetValue(HeaderNames.Cookie, out var headerValues));
- if (context.Request.Protocol == "HTTP/1.1")
+ if (context.Request.Protocol is "HTTP/1.1" or "HTTP/2")
{
Assert.Single(headerValues);
Assert.Equal(Cookies, headerValues);
}
- else if (context.Request.Protocol == "HTTP/2")
- {
-#if NET7_0_OR_GREATER
- // Fixed in kestrel in 7.0
- Assert.Single(headerValues);
- Assert.Equal(Cookies, headerValues);
-#else
- Assert.Equal(2, headerValues.Count);
- Assert.Equal(CookieA, headerValues[0]);
- Assert.Equal(CookieB, headerValues[1]);
-#endif
- }
else
{
Assert.Fail($"Unexpected HTTP protocol '{context.Request.Protocol}'");
diff --git a/test/ReverseProxy.FunctionalTests/TelemetryConsumptionTests.cs b/test/ReverseProxy.FunctionalTests/TelemetryConsumptionTests.cs
index eb22f5d8b..ae1d659ec 100644
--- a/test/ReverseProxy.FunctionalTests/TelemetryConsumptionTests.cs
+++ b/test/ReverseProxy.FunctionalTests/TelemetryConsumptionTests.cs
@@ -204,9 +204,7 @@ await test.Invoke(async uri =>
"OnRequestHeadersStop",
"OnResponseHeadersStart",
"OnResponseHeadersStop",
-#if NET8_0_OR_GREATER
"OnRedirect",
-#endif
"OnRequestHeadersStart",
"OnRequestHeadersStop",
"OnResponseHeadersStart",
diff --git a/test/ReverseProxy.FunctionalTests/WebSocketTests.cs b/test/ReverseProxy.FunctionalTests/WebSocketTests.cs
index 7891a2f4c..cfa7bb8f1 100644
--- a/test/ReverseProxy.FunctionalTests/WebSocketTests.cs
+++ b/test/ReverseProxy.FunctionalTests/WebSocketTests.cs
@@ -16,7 +16,6 @@
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Xunit;
@@ -36,7 +35,6 @@ public WebSocketTests(ITestOutputHelper output)
_output = output;
}
-#if NET7_0_OR_GREATER
public static IEnumerable WebSocketVersionNegotiation_TestData()
{
foreach (Version incomingVersion in new[] { HttpVersion.Version11, HttpVersion.Version20 })
@@ -103,14 +101,6 @@ public static IEnumerable WebSocketVersionNegotiation_TestData()
string expectedVersion = version == 1 ? "HTTP/1.1" : "HTTP/2";
-#if NET7_0
- if (version == 2 && destinationProtocols is HttpProtocols.Http1 or HttpProtocols.Http1AndHttp2 && !useHttpsOnDestination)
- {
- // https://github.com/dotnet/runtime/issues/80056
- continue;
- }
-#endif
-
yield return new object[] { incomingVersion, versionPolicy, destinationVersion, destinationProtocols, useHttpsOnDestination, expectedVersion, expectedProxyError, e2eWillFail };
}
}
@@ -124,14 +114,6 @@ public static IEnumerable WebSocketVersionNegotiation_TestData()
public async Task WebSocketVersionNegotiation(Version incomingVersion, HttpVersionPolicy versionPolicy, Version requestedDestinationVersion, HttpProtocols destinationProtocols, bool useHttpsOnDestination,
string expectedVersion, ForwarderError? expectedProxyError, bool e2eWillFail)
{
-#if !NET8_0_OR_GREATER
- if (OperatingSystem.IsMacOS() && useHttpsOnDestination && destinationProtocols != HttpProtocols.Http1)
- {
- // Does not support ALPN until .NET 8
- return;
- }
-#endif
-
using var cts = CreateTimer();
var test = CreateTestEnvironment();
@@ -175,7 +157,6 @@ await test.Invoke(async uri =>
Assert.Equal(1, proxyRequests);
Assert.Equal(expectedProxyError, error);
}
-#endif
[Theory]
[InlineData(WebSocketMessageType.Binary)]
@@ -301,20 +282,11 @@ await test.Invoke(async uri =>
}, cts.Token);
}
-#if NET7_0_OR_GREATER
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task WebSocket20_To_20(bool useHttps)
{
-#if !NET8_0_OR_GREATER
- if (OperatingSystem.IsMacOS() && useHttps)
- {
- // Does not support ALPN until .NET 8
- return;
- }
-#endif
-
using var cts = CreateTimer();
var test = CreateTestEnvironment();
@@ -338,14 +310,6 @@ await test.Invoke(async uri =>
[InlineData(false)]
public async Task WebSocket20_To_11(bool useHttps)
{
-#if !NET8_0_OR_GREATER
- if (OperatingSystem.IsMacOS() && useHttps)
- {
- // Does not support ALPN until .NET 8
- return;
- }
-#endif
-
using var cts = CreateTimer();
var test = CreateTestEnvironment();
@@ -369,14 +333,6 @@ await test.Invoke(async uri =>
[InlineData(false)]
public async Task WebSocket11_To_20(bool useHttps)
{
-#if !NET8_0_OR_GREATER
- if (OperatingSystem.IsMacOS() && useHttps)
- {
- // Does not support ALPN until .NET 8
- return;
- }
-#endif
-
using var cts = CreateTimer();
var test = CreateTestEnvironment();
@@ -496,9 +452,7 @@ await test.Invoke(async uri =>
[Theory]
[InlineData(HttpVersionPolicy.RequestVersionExact, true)]
-#if NET8_0_OR_GREATER
- [InlineData(HttpVersionPolicy.RequestVersionExact, false)] // Times out. https://github.com/dotnet/runtime/issues/80056
-#endif
+ [InlineData(HttpVersionPolicy.RequestVersionExact, false)]
[InlineData(HttpVersionPolicy.RequestVersionOrHigher, true)]
public async Task WebSocketCantFallbackFromH2(HttpVersionPolicy policy, bool useHttps)
{
@@ -516,23 +470,15 @@ await test.Invoke(async uri =>
using var client = new ClientWebSocket();
var webSocketsTarget = uri.Replace("https://", "wss://").Replace("http://", "ws://");
var targetUri = new Uri(new Uri(webSocketsTarget, UriKind.Absolute), "websockets");
-#if NET7_0_OR_GREATER
using var invoker = CreateInvoker();
var wse = await Assert.ThrowsAsync(() => client.ConnectAsync(targetUri, invoker, cts.Token));
-#else
- client.Options.RemoteCertificateValidationCallback = (_, _, _, _) => true;
- var wse = await Assert.ThrowsAsync(() => client.ConnectAsync(targetUri, cts.Token));
-#endif
Assert.Equal("The server returned status code '502' when status code '101' was expected.", wse.Message);
}, cts.Token);
}
-#endif
[Theory]
[InlineData(HttpProtocols.Http1)] // Checked by destination
-#if NET7_0_OR_GREATER
[InlineData(HttpProtocols.Http2)] // Checked by proxy
-#endif
public async Task InvalidKeyHeader_400(HttpProtocols destinationProtocol)
{
using var cts = CreateTimer();
@@ -553,17 +499,13 @@ public async Task InvalidKeyHeader_400(HttpProtocols destinationProtocol)
await test.Invoke(async uri =>
{
using var client = new ClientWebSocket();
-#if NET7_0_OR_GREATER
client.Options.CollectHttpResponseDetails = true;
-#endif
var webSocketsTarget = uri.Replace("https://", "wss://").Replace("http://", "ws://");
var targetUri = new Uri(new Uri(webSocketsTarget, UriKind.Absolute), "websockets");
client.Options.RemoteCertificateValidationCallback = (_, _, _, _) => true;
var wse = await Assert.ThrowsAsync(() => client.ConnectAsync(targetUri, cts.Token));
Assert.Equal("The server returned status code '400' when status code '101' was expected.", wse.Message);
-#if NET7_0_OR_GREATER
Assert.Equal(HttpStatusCode.BadRequest, client.HttpStatusCode);
-#endif
// TODO: Assert the version https://github.com/dotnet/runtime/issues/75353
}, cts.Token);
}
@@ -572,13 +514,8 @@ private async Task SendWebSocketRequestAsync(ClientWebSocket client, string uri,
{
var webSocketsTarget = uri.Replace("https://", "wss://").Replace("http://", "ws://");
var targetUri = new Uri(new Uri(webSocketsTarget, UriKind.Absolute), "websocketversion");
-#if NET7_0_OR_GREATER
using var invoker = CreateInvoker();
await client.ConnectAsync(targetUri, invoker, token);
-#else
- client.Options.RemoteCertificateValidationCallback = (_, _, _, _) => true;
- await client.ConnectAsync(targetUri, token);
-#endif
_output.WriteLine("Client connected.");
var buffer = new byte[1024];
diff --git a/test/ReverseProxy.FunctionalTests/WebSocketsTelemetryTests.cs b/test/ReverseProxy.FunctionalTests/WebSocketsTelemetryTests.cs
index 1cd876c30..e218c10c9 100644
--- a/test/ReverseProxy.FunctionalTests/WebSocketsTelemetryTests.cs
+++ b/test/ReverseProxy.FunctionalTests/WebSocketsTelemetryTests.cs
@@ -17,7 +17,6 @@
using Xunit;
using Xunit.Abstractions;
using Yarp.ReverseProxy.Common;
-using Yarp.ReverseProxy.Utilities;
using Yarp.Telemetry.Consumption;
using Yarp.Tests.Common;
@@ -83,7 +82,6 @@ await Task.WhenAll(
Assert.Equal(written, telemetry.MessagesWritten);
}
-#if NET7_0_OR_GREATER
[Fact]
public async Task Http2WebSocketsWork()
{
@@ -119,7 +117,6 @@ await Task.WhenAll(
Assert.Equal(read, telemetry!.MessagesRead);
Assert.Equal(written, telemetry.MessagesWritten);
}
-#endif
public enum Behavior
{
@@ -446,7 +443,6 @@ public void OnWebSocketClosed(DateTime timestamp, DateTime establishedTime, WebS
}
}
-#if NET7_0_OR_GREATER
private static HttpMessageInvoker CreateInvoker()
{
var handler = new SocketsHttpHandler
@@ -459,5 +455,4 @@ private static HttpMessageInvoker CreateInvoker()
handler.SslOptions.RemoteCertificateValidationCallback = (_, _, _, _) => true;
return new HttpMessageInvoker(handler);
}
-#endif
}
diff --git a/test/ReverseProxy.Tests/Configuration/ConfigProvider/ConfigurationConfigProviderTests.cs b/test/ReverseProxy.Tests/Configuration/ConfigProvider/ConfigurationConfigProviderTests.cs
index 2f678525b..5b7c310b5 100644
--- a/test/ReverseProxy.Tests/Configuration/ConfigProvider/ConfigurationConfigProviderTests.cs
+++ b/test/ReverseProxy.Tests/Configuration/ConfigProvider/ConfigurationConfigProviderTests.cs
@@ -141,13 +141,9 @@ public class ConfigurationConfigProviderTests
RouteId = "routeA",
ClusterId = "cluster1",
AuthorizationPolicy = "Default",
-#if NET7_0_OR_GREATER
RateLimiterPolicy = "Default",
-#endif
-#if NET8_0_OR_GREATER
TimeoutPolicy = "Default",
Timeout = TimeSpan.Zero,
-#endif
CorsPolicy = "Default",
Order = -1,
MaxRequestBodySize = -1,
diff --git a/test/ReverseProxy.Tests/Configuration/ConfigValidatorTests.cs b/test/ReverseProxy.Tests/Configuration/ConfigValidatorTests.cs
index b16771f0e..8cfc575b9 100644
--- a/test/ReverseProxy.Tests/Configuration/ConfigValidatorTests.cs
+++ b/test/ReverseProxy.Tests/Configuration/ConfigValidatorTests.cs
@@ -4,13 +4,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
-#if NET7_0_OR_GREATER
using Microsoft.AspNetCore.Builder;
-#endif
using Microsoft.AspNetCore.Cors.Infrastructure;
-#if NET7_0_OR_GREATER
using Microsoft.AspNetCore.RateLimiting;
-#endif
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Xunit;
@@ -607,7 +603,7 @@ public async Task Rejects_ReservedAuthorizationPolicyIsUsed(string authorization
Assert.NotEmpty(result);
Assert.Contains(result, err => err.Message.Equals($"The application has registered an authorization policy named '{authorizationPolicy}' that conflicts with the reserved authorization policy name used on this route. The registered policy name needs to be changed for this route to function."));
}
-#if NET8_0_OR_GREATER
+
[Theory]
[InlineData(null)]
[InlineData("")]
@@ -745,7 +741,7 @@ public async Task Rejects_TimeoutWithTimeoutPolicy()
Assert.NotEmpty(result);
Assert.Contains(result, err => err.Message.Equals("Timeout policy 'unknown' not found for route 'route1'."));
}
-#endif
+
[Theory]
[InlineData(null)]
[InlineData("")]
@@ -854,7 +850,6 @@ public async Task Rejects_ReservedCorsPolicyIsUsed(string corsPolicy)
Assert.Contains(result, err => err.Message.Equals($"The application has registered a CORS policy named '{corsPolicy}' that conflicts with the reserved CORS policy name used on this route. The registered policy name needs to be changed for this route to function."));
}
-#if NET7_0_OR_GREATER
[Theory]
[InlineData("Default")]
[InlineData("Disable")]
@@ -927,7 +922,6 @@ public async Task Rejects_InvalidRateLimiterPolicy(string rateLimiterPolicy)
Assert.NotEmpty(result);
Assert.Contains(result, err => err.Message.Contains($"RateLimiter policy '{rateLimiterPolicy}' not found"));
}
-#endif
[Fact]
public async Task EmptyCluster_Works()
diff --git a/test/ReverseProxy.Tests/Configuration/RouteConfigTests.cs b/test/ReverseProxy.Tests/Configuration/RouteConfigTests.cs
index 82b855e8f..ebb0647ca 100644
--- a/test/ReverseProxy.Tests/Configuration/RouteConfigTests.cs
+++ b/test/ReverseProxy.Tests/Configuration/RouteConfigTests.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
-using System.Threading;
using Xunit;
namespace Yarp.ReverseProxy.Configuration.Tests;
@@ -17,13 +16,9 @@ public void Equals_Positive()
var a = new RouteConfig()
{
AuthorizationPolicy = "a",
-#if NET7_0_OR_GREATER
RateLimiterPolicy = "rl",
-#endif
-#if NET8_0_OR_GREATER
TimeoutPolicy = "t",
Timeout = TimeSpan.FromSeconds(1),
-#endif
ClusterId = "c",
CorsPolicy = "co",
Match = new RouteMatch()
@@ -52,13 +47,9 @@ public void Equals_Positive()
var b = new RouteConfig()
{
AuthorizationPolicy = "A",
-#if NET7_0_OR_GREATER
RateLimiterPolicy = "RL",
-#endif
-#if NET8_0_OR_GREATER
TimeoutPolicy = "T",
Timeout = TimeSpan.FromSeconds(1),
-#endif
ClusterId = "C",
CorsPolicy = "Co",
Match = new RouteMatch()
@@ -98,13 +89,9 @@ public void Equals_Negative()
var a = new RouteConfig()
{
AuthorizationPolicy = "a",
-#if NET7_0_OR_GREATER
RateLimiterPolicy = "rl",
-#endif
-#if NET8_0_OR_GREATER
TimeoutPolicy = "t",
Timeout = TimeSpan.FromSeconds(1),
-#endif
ClusterId = "c",
CorsPolicy = "co",
Match = new RouteMatch()
@@ -137,13 +124,9 @@ public void Equals_Negative()
var f = a with { Metadata = new Dictionary() { { "f", "f1" } } };
var g = a with { Order = null };
var h = a with { RouteId = "h" };
-#if NET7_0_OR_GREATER
var i = a with { RateLimiterPolicy = "i" };
-#endif
-#if NET8_0_OR_GREATER
var j = a with { TimeoutPolicy = "j" };
var k = a with { Timeout = TimeSpan.FromSeconds(107) };
-#endif
Assert.False(a.Equals(b));
Assert.False(a.Equals(c));
@@ -152,13 +135,9 @@ public void Equals_Negative()
Assert.False(a.Equals(f));
Assert.False(a.Equals(g));
Assert.False(a.Equals(h));
-#if NET7_0_OR_GREATER
Assert.False(a.Equals(i));
-#endif
-#if NET8_0_OR_GREATER
Assert.False(a.Equals(j));
Assert.False(a.Equals(k));
-#endif
}
[Fact]
@@ -173,9 +152,7 @@ public void RouteConfig_CanBeJsonSerialized()
var route1 = new RouteConfig()
{
AuthorizationPolicy = "a",
-#if NET7_0_OR_GREATER
RateLimiterPolicy = "rl",
-#endif
ClusterId = "c",
CorsPolicy = "co",
Match = new RouteMatch()
diff --git a/test/ReverseProxy.Tests/Configuration/YarpOutputCachePolicyProviderTests.cs b/test/ReverseProxy.Tests/Configuration/YarpOutputCachePolicyProviderTests.cs
index 3d073901e..e554a587c 100644
--- a/test/ReverseProxy.Tests/Configuration/YarpOutputCachePolicyProviderTests.cs
+++ b/test/ReverseProxy.Tests/Configuration/YarpOutputCachePolicyProviderTests.cs
@@ -1,12 +1,8 @@
// 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.Threading.Tasks;
-using System.Threading.RateLimiting;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.RateLimiting;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
@@ -35,4 +31,3 @@ public async Task GetPolicyAsync_Works()
Assert.NotNull(await outputCachePolicyProvider.GetPolicyAsync("customPolicy"));
}
}
-#endif
diff --git a/test/ReverseProxy.Tests/Configuration/YarpRateLimiterPolicyProviderTests.cs b/test/ReverseProxy.Tests/Configuration/YarpRateLimiterPolicyProviderTests.cs
index 5e4f27c88..cb7eb339d 100644
--- a/test/ReverseProxy.Tests/Configuration/YarpRateLimiterPolicyProviderTests.cs
+++ b/test/ReverseProxy.Tests/Configuration/YarpRateLimiterPolicyProviderTests.cs
@@ -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.
-#if NET7_0_OR_GREATER
using System;
using System.Threading.Tasks;
using System.Threading.RateLimiting;
@@ -37,4 +36,3 @@ public async Task GetPolicyAsync_Works()
Assert.NotNull(await rateLimiterPolicyProvider.GetPolicyAsync("customPolicy"));
}
}
-#endif
diff --git a/test/ReverseProxy.Tests/Forwarder/HttpForwarderTests.cs b/test/ReverseProxy.Tests/Forwarder/HttpForwarderTests.cs
index c26e108de..c7b44feca 100644
--- a/test/ReverseProxy.Tests/Forwarder/HttpForwarderTests.cs
+++ b/test/ReverseProxy.Tests/Forwarder/HttpForwarderTests.cs
@@ -18,7 +18,6 @@
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
using Moq;
@@ -1060,14 +1059,6 @@ private class TestBodyDetector : IHttpRequestBodyDetectionFeature
}
[Theory]
-#if !NET7_0_OR_GREATER // Fixed in .NET 7.0
- // This is an invalid format per spec but may happen due to https://github.com/dotnet/aspnetcore/issues/26461
- [InlineData("testA=A_Cookie", "testB=B_Cookie", "testC=C_Cookie")]
- [InlineData("testA=A_Value", "testB=B_Value", "testC=C_Value")]
- [InlineData("testA=A_Value, testB=B_Value", "testC=C_Value")]
- [InlineData("testA=A_Value", "", "testB=B_Value, testC=C_Value")]
- [InlineData("", "")]
-#endif
[InlineData("testA=A_Value, testB=B_Value, testC=C_Value")]
public async Task RequestWithCookieHeaders(params string[] cookies)
{
diff --git a/test/ReverseProxy.Tests/Forwarder/HttpTransformerTests.cs b/test/ReverseProxy.Tests/Forwarder/HttpTransformerTests.cs
index 2b360de98..1b472a81b 100644
--- a/test/ReverseProxy.Tests/Forwarder/HttpTransformerTests.cs
+++ b/test/ReverseProxy.Tests/Forwarder/HttpTransformerTests.cs
@@ -13,7 +13,6 @@
using Microsoft.Net.Http.Headers;
using Xunit;
using Yarp.ReverseProxy.Transforms;
-using Yarp.ReverseProxy.Transforms.Builder;
using Yarp.ReverseProxy.Transforms.Builder.Tests;
using Yarp.Tests.Common;
diff --git a/test/ReverseProxy.Tests/Forwarder/RequestUtilitiesTests.cs b/test/ReverseProxy.Tests/Forwarder/RequestUtilitiesTests.cs
index 5a47a08a1..618ba2d98 100644
--- a/test/ReverseProxy.Tests/Forwarder/RequestUtilitiesTests.cs
+++ b/test/ReverseProxy.Tests/Forwarder/RequestUtilitiesTests.cs
@@ -98,7 +98,6 @@ public void GetHttpMethod_Invalid_Throws(string method)
// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
[InlineData("http://localhost/base/", "/path/!$&'()*+,;=:@/%?#[]", "?query", "http://localhost/base/path/!$&'()*+,;=:@/%25%3F%23%5B%5D?query")]
- // #if NET6.0 [InlineData("http://localhost/base/", "/path/", "?query%4A", "http://localhost/base/path/?query%4A")] // https://github.com/dotnet/runtime/issues/58057
// PathString should be fully un-escaped to start with and QueryString should be fully escaped.
[InlineData("http://localhost/base/", "/path/%2F%20", "?query%20", "http://localhost/base/path/%252F%2520?query%20")]
public void MakeDestinationAddress(string destinationPrefix, string path, string query, string expected)
@@ -128,11 +127,10 @@ public void ValidPathCharacters()
'a', 'b', 'c', 'd', 'e', 'f','g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'~'
};
+
foreach (var c in valids)
{
- var isValid = RequestUtilities.IsValidPathChar(c);
-
- Assert.True(isValid, c.ToString());
+ Assert.Equal($"/{c}", RequestUtilities.EncodePath($"/{c}"));
}
}
@@ -146,11 +144,10 @@ public void InvalidPathCharacters()
(char)0x10, (char)0x11, (char)0x02, (char)0x13, (char)0x14, (char)0x15, (char)0x16, (char)0x10, (char)0x17, (char)0x18, (char)0x19, (char)0x1A, (char)0x1B, (char)0x1C, (char)0x1D, (char)0x1E, (char)0x1F,
' ', '"', '#', '%', '<', '>', '?', '[', '\\', ']', '^', '`', '{', '|', '}'
};
+
foreach (var c in invalids)
{
- var isValid = RequestUtilities.IsValidPathChar(c);
-
- Assert.False(isValid, c.ToString());
+ Assert.Equal($"/%{(int)c:X2}", RequestUtilities.EncodePath($"/{c}"));
}
}
diff --git a/test/ReverseProxy.Tests/Model/ProxyPipelineInitializerMiddlewareTests.cs b/test/ReverseProxy.Tests/Model/ProxyPipelineInitializerMiddlewareTests.cs
index a26a6a77d..5d3c67854 100644
--- a/test/ReverseProxy.Tests/Model/ProxyPipelineInitializerMiddlewareTests.cs
+++ b/test/ReverseProxy.Tests/Model/ProxyPipelineInitializerMiddlewareTests.cs
@@ -7,9 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
-#if NET8_0_OR_GREATER
using Microsoft.AspNetCore.Http.Timeouts;
-#endif
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Moq;
@@ -124,7 +122,6 @@ public async Task Invoke_NoHealthyEndpoints_CallsNext()
Assert.Equal(StatusCodes.Status418ImATeapot, httpContext.Response.StatusCode);
}
-#if NET8_0_OR_GREATER
[Theory]
[InlineData(1)]
[InlineData(Timeout.Infinite)]
@@ -162,7 +159,6 @@ public async Task Invoke_MissingTimeoutMiddleware_RefuseRequest(int timeoutMs)
await Assert.ThrowsAsync(() => sut.Invoke(httpContext));
}
}
-#endif
private static Endpoint CreateAspNetCoreEndpoint(RouteModel routeConfig, Action configure = null)
{
diff --git a/test/ReverseProxy.Tests/Routing/ProxyEndpointFactoryTests.cs b/test/ReverseProxy.Tests/Routing/ProxyEndpointFactoryTests.cs
index 3a504b9e0..251cdde30 100644
--- a/test/ReverseProxy.Tests/Routing/ProxyEndpointFactoryTests.cs
+++ b/test/ReverseProxy.Tests/Routing/ProxyEndpointFactoryTests.cs
@@ -8,12 +8,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Cors.Infrastructure;
-#if NET8_0_OR_GREATER
using Microsoft.AspNetCore.Http.Timeouts;
-#endif
-#if NET7_0_OR_GREATER
using Microsoft.AspNetCore.RateLimiting;
-#endif
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Patterns;
using Microsoft.Extensions.DependencyInjection;
@@ -330,7 +326,6 @@ public void AddEndpoint_NoAuth_Works()
Assert.Null(routeEndpoint.Metadata.GetMetadata());
}
-#if NET7_0_OR_GREATER
[Fact]
public void AddEndpoint_DefaultRateLimiter_Works()
{
@@ -423,8 +418,7 @@ public void AddEndpoint_NoRateLimiter_Works()
Assert.Null(routeEndpoint.Metadata.GetMetadata());
Assert.Null(routeEndpoint.Metadata.GetMetadata());
}
-#endif
-#if NET8_0_OR_GREATER
+
[Fact]
public void AddEndpoint_CustomTimeoutPolicy_Works()
{
@@ -521,7 +515,6 @@ public void AddEndpoint_NoTimeoutPolicy_Works()
Assert.Null(routeEndpoint.Metadata.GetMetadata());
Assert.Null(routeEndpoint.Metadata.GetMetadata());
}
-#endif
[Fact]
public void AddEndpoint_DefaultCors_Works()
diff --git a/test/ReverseProxy.Tests/Transforms/Builder/TransformBuilderTests.cs b/test/ReverseProxy.Tests/Transforms/Builder/TransformBuilderTests.cs
index e1b04c4a4..97507ca5f 100644
--- a/test/ReverseProxy.Tests/Transforms/Builder/TransformBuilderTests.cs
+++ b/test/ReverseProxy.Tests/Transforms/Builder/TransformBuilderTests.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Linq.Expressions;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
diff --git a/test/Tests.Common/TestTimeProvider.cs b/test/Tests.Common/TestTimeProvider.cs
index e4eec1aed..cb7c627e0 100644
--- a/test/Tests.Common/TestTimeProvider.cs
+++ b/test/Tests.Common/TestTimeProvider.cs
@@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
diff --git a/testassets/ReverseProxy.Code/Program.cs b/testassets/ReverseProxy.Code/Program.cs
index 84773c346..5d3eecb1c 100644
--- a/testassets/ReverseProxy.Code/Program.cs
+++ b/testassets/ReverseProxy.Code/Program.cs
@@ -29,9 +29,7 @@
{
Path = "{**catch-all}"
},
-#if NET8_0_OR_GREATER
Timeout = TimeSpan.FromSeconds(5),
-#endif
}
};
var clusters = new[]
@@ -100,7 +98,6 @@
services.AddSingleton, ForwarderMetricsConsumer>();
services.AddTelemetryConsumer();
services.AddTelemetryListeners();
-#if NET8_0_OR_GREATER
services.AddRequestTimeouts(o =>
{
o.DefaultPolicy = new Microsoft.AspNetCore.Http.Timeouts.RequestTimeoutPolicy()
@@ -109,14 +106,11 @@
TimeoutStatusCode = StatusCodes.Status418ImATeapot,
};
});
-#endif
var app = builder.Build();
app.UseAuthorization();
-#if NET8_0_OR_GREATER
app.UseRequestTimeouts();
-#endif
app.MapControllers();
app.MapReverseProxy(proxyPipeline =>