mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-17 23:57:03 +01:00
Move PortUtils.cs
This commit is contained in:
@@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using WireMock.Http;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -43,7 +43,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
Urls.Add(uriPrefix);
|
||||
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
PortUtils.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
Ports.Add(port);
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ namespace WireMock.Owin
|
||||
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("http://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
PortUtils.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(System.Net.IPAddress.Any, port);
|
||||
}
|
||||
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
PortUtils.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(System.Net.IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Http;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -30,7 +31,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
Urls.Add(uriPrefix);
|
||||
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
PortUtils.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
Ports.Add(port);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseProviders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Server
|
||||
@@ -199,7 +200,7 @@ namespace WireMock.Server
|
||||
}
|
||||
else
|
||||
{
|
||||
int port = settings.Port > 0 ? settings.Port.Value : PortUtil.FindFreeTcpPort();
|
||||
int port = settings.Port > 0 ? settings.Port.Value : PortUtils.FindFreeTcpPort();
|
||||
Urls = new[] { $"{(settings.UseSSL == true ? "https" : "http")}://localhost:{port}" };
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WireMock.Http
|
||||
namespace WireMock.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Port Utility class
|
||||
/// </summary>
|
||||
public static class PortUtil
|
||||
public static class PortUtils
|
||||
{
|
||||
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)/?", RegexOptions.Compiled);
|
||||
|
||||
Reference in New Issue
Block a user