Add IgnoreCase option to ProxyUrlReplaceSettings (#925)

* Add IgnoreCase option to ProxyUrlReplaceSettings

* fix
This commit is contained in:
Stef Heyenrath
2023-04-23 11:56:08 +02:00
committed by GitHub
parent 9ef8bd0b7b
commit 0a2763c06e
4 changed files with 36 additions and 1 deletions

View File

@@ -15,4 +15,9 @@ public class ProxyUrlReplaceSettingsModel
/// The new path value to replace the old value with
/// </summary>
public string NewValue { get; set; } = null!;
/// <summary>
/// Defines if the case should be ignore when replacing.
/// </summary>
public bool IgnoreCase { get; set; }
}

View File

@@ -0,0 +1,15 @@
#if NET451 || NET452 || NET46 || NET451 || NET461 || NETSTANDARD1_3 || NETSTANDARD2_0
using System.Text.RegularExpressions;
// ReSharper disable once CheckNamespace
namespace System;
internal static class StringExtensions
{
public static string Replace(this string text, string oldValue, string newValue, StringComparison stringComparison)
{
var options = stringComparison == StringComparison.OrdinalIgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None;
return Regex.Replace(text, oldValue, newValue, options);
}
}
#endif

View File

@@ -38,7 +38,17 @@ internal class ProxyHelper
// Create HttpRequestMessage
var replaceSettings = proxyAndRecordSettings.ReplaceSettings;
var proxyUrl = replaceSettings is not null ? url.Replace(replaceSettings.OldValue, replaceSettings.NewValue) : url;
string proxyUrl;
if (replaceSettings is not null)
{
var stringComparison = replaceSettings.IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
proxyUrl = url.Replace(replaceSettings.OldValue, replaceSettings.NewValue, stringComparison);
}
else
{
proxyUrl = url;
}
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, proxyUrl);
// Call the URL

View File

@@ -14,4 +14,9 @@ public class ProxyUrlReplaceSettings
/// The new path value to replace the old value with
/// </summary>
public string NewValue { get; set; } = null!;
/// <summary>
/// Defines if the case should be ignore when replacing.
/// </summary>
public bool IgnoreCase { get; set; }
}