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