mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-29 19:20:44 +02:00
Add IgnoreCase option to ProxyUrlReplaceSettings (#925)
* Add IgnoreCase option to ProxyUrlReplaceSettings * fix
This commit is contained in:
@@ -15,4 +15,9 @@ public class ProxyUrlReplaceSettingsModel
|
|||||||
/// The new path value to replace the old value with
|
/// The new path value to replace the old value with
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string NewValue { get; set; } = null!;
|
public string NewValue { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines if the case should be ignore when replacing.
|
||||||
|
/// </summary>
|
||||||
|
public bool IgnoreCase { get; set; }
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
@@ -38,7 +38,17 @@ internal class ProxyHelper
|
|||||||
|
|
||||||
// Create HttpRequestMessage
|
// Create HttpRequestMessage
|
||||||
var replaceSettings = proxyAndRecordSettings.ReplaceSettings;
|
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);
|
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, proxyUrl);
|
||||||
|
|
||||||
// Call the URL
|
// Call the URL
|
||||||
|
|||||||
@@ -14,4 +14,9 @@ public class ProxyUrlReplaceSettings
|
|||||||
/// The new path value to replace the old value with
|
/// The new path value to replace the old value with
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string NewValue { get; set; } = null!;
|
public string NewValue { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines if the case should be ignore when replacing.
|
||||||
|
/// </summary>
|
||||||
|
public bool IgnoreCase { get; set; }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user