diff --git a/examples/WireMock.Net.StandAlone.NETCoreApp/Properties/launchSettings.json b/examples/WireMock.Net.StandAlone.NETCoreApp/Properties/launchSettings.json
new file mode 100644
index 00000000..c52dce78
--- /dev/null
+++ b/examples/WireMock.Net.StandAlone.NETCoreApp/Properties/launchSettings.json
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "WireMock.Net.StandAlone.NETCoreApp": {
+ "commandName": "Project",
+ "commandLineArgs": "--Urls http://*:9090"
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock.Net/Http/PortUtil.cs b/src/WireMock.Net/Http/PortUtil.cs
index 223d2535..0f101c75 100644
--- a/src/WireMock.Net/Http/PortUtil.cs
+++ b/src/WireMock.Net/Http/PortUtil.cs
@@ -1,13 +1,16 @@
using System.Net;
using System.Net.Sockets;
+using System.Text.RegularExpressions;
namespace WireMock.Http
{
///
- /// The ports.
+ /// Utility class
///
public static class PortUtil
{
+ private static readonly Regex UrlDetailsRegex = new Regex(@"^(?\w+)://[^/]+?(?\d+)?/", RegexOptions.Compiled);
+
///
/// The find free TCP port.
///
@@ -30,5 +33,24 @@ namespace WireMock.Http
tcpListener?.Stop();
}
}
+
+ ///
+ /// Extract a proto and port from a URL.
+ ///
+ public static bool TryExtractProtocolAndPort(string url, out string proto, out int port)
+ {
+ proto = null;
+ port = -1;
+
+ Match m = UrlDetailsRegex.Match(url);
+ if (m.Success)
+ {
+ proto = m.Groups["proto"].Value;
+
+ return int.TryParse(m.Groups["port"].Value, out port);
+ }
+
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
index abac138a..7b8da81b 100644
--- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
+++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs
@@ -1,5 +1,4 @@
#if NETSTANDARD
-using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -8,6 +7,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using WireMock.Http;
using WireMock.Validation;
namespace WireMock.Owin
@@ -20,7 +20,7 @@ namespace WireMock.Owin
public bool IsStarted { get; private set; }
- public List Urls { get; } = new List();
+ public List Urls { get; } = new List();
public List Ports { get; } = new List();
@@ -31,9 +31,12 @@ namespace WireMock.Owin
foreach (string uriPrefix in uriPrefixes)
{
- var uri = new Uri(uriPrefix);
- Urls.Add(uri);
- Ports.Add(uri.Port);
+ Urls.Add(uriPrefix);
+
+ int port;
+ string host;
+ PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
+ Ports.Add(port);
}
_options = options;
diff --git a/src/WireMock.Net/Owin/IOwinSelfHost.cs b/src/WireMock.Net/Owin/IOwinSelfHost.cs
index 2d6542ff..2a378b2f 100644
--- a/src/WireMock.Net/Owin/IOwinSelfHost.cs
+++ b/src/WireMock.Net/Owin/IOwinSelfHost.cs
@@ -15,12 +15,12 @@ namespace WireMock.Owin
bool IsStarted { get; }
///
- /// Gets the url.
+ /// Gets the urls.
///
///
/// The urls.
///
- List Urls { get; }
+ List Urls { get; }
///
/// Gets the ports.
diff --git a/src/WireMock.Net/Owin/OwinSelfHost.cs b/src/WireMock.Net/Owin/OwinSelfHost.cs
index bfdde820..9d866d55 100644
--- a/src/WireMock.Net/Owin/OwinSelfHost.cs
+++ b/src/WireMock.Net/Owin/OwinSelfHost.cs
@@ -7,6 +7,7 @@ using JetBrains.Annotations;
using WireMock.Validation;
using Owin;
using Microsoft.Owin.Hosting;
+using WireMock.Http;
namespace WireMock.Owin
{
@@ -14,7 +15,7 @@ namespace WireMock.Owin
{
private readonly WireMockMiddlewareOptions _options;
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
- private System.Threading.Thread _internalThread;
+ private Thread _internalThread;
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
{
@@ -23,9 +24,12 @@ namespace WireMock.Owin
foreach (string uriPrefix in uriPrefixes)
{
- var uri = new Uri(uriPrefix);
- Urls.Add(uri);
- Ports.Add(uri.Port);
+ Urls.Add(uriPrefix);
+
+ int port;
+ string host;
+ PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
+ Ports.Add(port);
}
_options = options;
@@ -33,7 +37,7 @@ namespace WireMock.Owin
public bool IsStarted { get; private set; }
- public List Urls { get; } = new List();
+ public List Urls { get; } = new List();
public List Ports { get; } = new List();
@@ -76,7 +80,7 @@ namespace WireMock.Owin
var servers = new List();
foreach (var url in Urls)
{
- servers.Add(WebApp.Start(url.ToString(), startup));
+ servers.Add(WebApp.Start(url, startup));
}
IsStarted = true;
diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj
index 6491c556..9d84c056 100644
--- a/src/WireMock.Net/WireMock.Net.csproj
+++ b/src/WireMock.Net/WireMock.Net.csproj
@@ -3,7 +3,7 @@
Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.
WireMock.Net
- 1.0.2.2
+ 1.0.2.3
Alexandre Victoor;Stef Heyenrath
net45;net452;net46;netstandard1.3
true