This commit is contained in:
Stef Heyenrath
2026-02-14 11:41:25 +01:00
parent 99f42fb255
commit 6cc18e796c
55 changed files with 164 additions and 398 deletions

View File

@@ -1,14 +1,7 @@
// Copyright © WireMock.Net
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
//#if !USE_ASPNETCORE
//using IResponse = Microsoft.Owin.IOwinResponse;
//#else
//using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
//#endif
namespace WireMock.Owin.Mappers;
/// <summary>

View File

@@ -2,14 +2,9 @@
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
//#if USE_ASPNETCORE
//using System.Security.Cryptography.X509Certificates;
//#endif
using System.Text.Json.Serialization;
using Stef.Validation;
using WireMock.Models;
using WireMock.Owin;
@@ -83,11 +78,10 @@ public class RequestMessage : IRequestMessage
/// <inheritdoc />
public byte[]? BodyAsBytes { get; }
//#if MIMEKIT
/// <inheritdoc />
[Newtonsoft.Json.JsonIgnore] // Issue 1001
[JsonIgnore]
public Models.Mime.IMimeMessageData? BodyAsMimeMessage { get; }
//#endif
/// <inheritdoc />
public string? DetectedBodyType { get; }
@@ -110,10 +104,8 @@ public class RequestMessage : IRequestMessage
/// <inheritdoc />
public string Origin { get; }
//#if USE_ASPNETCORE
/// <inheritdoc />
public X509Certificate2? ClientCertificate { get; }
//#endif
/// <summary>
/// Used for Unit Testing
@@ -136,10 +128,8 @@ public class RequestMessage : IRequestMessage
IBodyData? bodyData = null,
IDictionary<string, string[]>? headers = null,
IDictionary<string, string>? cookies = null,
string httpVersion = "1.1"
//#if USE_ASPNETCORE
, X509Certificate2? clientCertificate = null
//#endif
string httpVersion = "1.1",
X509Certificate2? clientCertificate = null
)
{
Guard.NotNull(urlDetails);
@@ -179,16 +169,11 @@ public class RequestMessage : IRequestMessage
Query = QueryStringParser.Parse(RawQuery, options?.QueryParameterMultipleValueSupport);
QueryIgnoreCase = new Dictionary<string, WireMockList<string>>(Query, StringComparer.OrdinalIgnoreCase);
//#if USE_ASPNETCORE
ClientCertificate = clientCertificate;
//#endif
//#if MIMEKIT
if (TypeLoader.TryLoadStaticInstance<IMimeKitUtils>(out var mimeKitUtils) && mimeKitUtils.TryGetMimeMessage(this, out var mimeMessage))
{
BodyAsMimeMessage = mimeMessage;
}
//#endif
}
/// <inheritdoc />

View File

@@ -218,7 +218,6 @@ internal class MatcherMapper
model.ContentTypeMatcher = Map(mimePartMatcher.ContentTypeMatcher);
break;
//#if PROTOBUF
case IProtoBufMatcher protoBufMatcher:
protoBufMatcher.ProtoDefinition().Value(id => model.Pattern = id, texts =>
{
@@ -235,7 +234,6 @@ internal class MatcherMapper
model.ProtoBufMessageType = protoBufMatcher.MessageType;
model.ContentMatcher = Map(protoBufMatcher.Matcher);
break;
//#endif
}
afterMap?.Invoke(model);

View File

@@ -330,12 +330,10 @@ public partial class WireMockServer
InitSettings(_settings);
//#if USE_ASPNETCORE
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
{
_settings.CorsPolicyOptions = corsPolicyOptions;
}
//#endif
WireMockMiddlewareOptionsHelper.InitFromSettings(_settings, _options, o =>
{
@@ -344,11 +342,9 @@ public partial class WireMockServer
o.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
}
//#if USE_ASPNETCORE
o.CorsPolicyOptions = corsPolicyOptions;
o.ClientCertificateMode = (Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode) _settings.ClientCertificateMode;
o.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
//#endif
});
return ResponseMessageBuilder.Create(200, "Settings updated");

View File

@@ -24,7 +24,6 @@ internal static class WireMockHandlebarsHelpers
GetBaseDirectory(),
};
//#if !NETSTANDARD1_3_OR_GREATER
void Add(string? path, ICollection<string> customHelperPaths)
{
if (!string.IsNullOrEmpty(path))
@@ -36,7 +35,7 @@ internal static class WireMockHandlebarsHelpers
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), paths);
Add(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName), paths);
//#endif
o.CustomHelperPaths = paths;
o.Categories = settings.HandlebarsSettings?.AllowedHandlebarsHelpers ?? HandlebarsSettings.DefaultAllowedHandlebarsHelpers;

View File

@@ -18,12 +18,11 @@ internal static class CultureInfoUtils
try
{
//#if !NETSTANDARD1_3
if (int.TryParse(value, out var culture))
{
return new CultureInfo(culture);
}
//#endif
if (string.Equals(value, nameof(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase))
{
return CultureInfo.CurrentCulture;

View File

@@ -1,14 +1,8 @@
// Copyright © WireMock.Net
using System;
using Microsoft.AspNetCore.Http;
using WireMock.Models;
using Stef.Validation;
//#if !USE_ASPNETCORE
//using Microsoft.Owin;
//#else
//using Microsoft.AspNetCore.Http;
//#endif
namespace WireMock.Util;

View File

@@ -1,7 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Stef.Validation;
@@ -10,9 +8,7 @@ namespace WireMock.RegularExpressions;
/// <summary>
/// Extension to the <see cref="Regex"/> object, adding support for GUID tokens for matching on.
/// </summary>
//#if !NETSTANDARD1_3
[Serializable]
//#endif
internal class RegexExtended : Regex
{
/// <inheritdoc cref="Regex"/>

View File

@@ -148,7 +148,6 @@ public class WireMockServerSettings
[JsonIgnore]
public Action<object>? PostWireMockMiddlewareInit { get; set; }
//#if USE_ASPNETCORE
/// <summary>
/// Action which is called with IServiceCollection when ASP.NET Core DI is being configured. [Optional]
/// </summary>
@@ -161,7 +160,6 @@ public class WireMockServerSettings
/// </summary>
[PublicAPI]
public CorsPolicyOptions? CorsPolicyOptions { get; set; }
//#endif
/// <summary>
/// The IWireMockLogger which logs Debug, Info, Warning or Error
@@ -246,7 +244,6 @@ public class WireMockServerSettings
[PublicAPI]
public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true;
//#if USE_ASPNETCORE
/// <summary>
/// Client certificate mode for the server
/// </summary>
@@ -257,8 +254,7 @@ public class WireMockServerSettings
/// Whether to accept any client certificate
/// </summary>
public bool AcceptAnyClientCertificate { get; set; }
//#endif
/// <summary>
/// Defines the global IWebhookSettings to use.
/// </summary>

View File

@@ -22,10 +22,7 @@ internal static class CompressionUtils
using var compressedStream = new MemoryStream();
using var zipStream = Create(contentEncoding, compressedStream, CompressionMode.Compress);
zipStream.Write(data, 0, data.Length);
//#if !NETSTANDARD1_3
zipStream.Close();
//#endif
return compressedStream.ToArray();
}

View File

@@ -1,10 +1,8 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using Stef.Validation;
@@ -142,16 +140,13 @@ internal static class TypeLoader
private static bool TryFindTypeInDlls<TInterface>(string? implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class
{
//#if NETSTANDARD1_3
// var directoriesToSearch = new[] { AppContext.BaseDirectory };
//#else
var processDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName);
var processDirectory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName);
var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var directoriesToSearch = new[] { processDirectory, assemblyDirectory }
.Where(d => !string.IsNullOrEmpty(d))
.Distinct()
.ToArray();
//#endif
foreach (var directory in directoriesToSearch)
{
foreach (var file in Directory.GetFiles(directory!, "*.dll"))