* Support for http://*:9090 urls

* Update version to 1.0.2.3
This commit is contained in:
Stef Heyenrath
2017-08-08 22:58:12 +02:00
committed by GitHub
parent ef73accc9a
commit 2aee658dfa
6 changed files with 52 additions and 15 deletions

View File

@@ -0,0 +1,8 @@
{
"profiles": {
"WireMock.Net.StandAlone.NETCoreApp": {
"commandName": "Project",
"commandLineArgs": "--Urls http://*:9090"
}
}
}

View File

@@ -1,13 +1,16 @@
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
namespace WireMock.Http
{
/// <summary>
/// The ports.
/// Utility class
/// </summary>
public static class PortUtil
{
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)?/", RegexOptions.Compiled);
/// <summary>
/// The find free TCP port.
/// </summary>
@@ -30,5 +33,24 @@ namespace WireMock.Http
tcpListener?.Stop();
}
}
/// <summary>
/// Extract a proto and port from a URL.
/// </summary>
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;
}
}
}

View File

@@ -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<Uri> Urls { get; } = new List<Uri>();
public List<string> Urls { get; } = new List<string>();
public List<int> Ports { get; } = new List<int>();
@@ -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;

View File

@@ -15,12 +15,12 @@ namespace WireMock.Owin
bool IsStarted { get; }
/// <summary>
/// Gets the url.
/// Gets the urls.
/// </summary>
/// <value>
/// The urls.
/// </value>
List<Uri> Urls { get; }
List<string> Urls { get; }
/// <summary>
/// Gets the ports.

View File

@@ -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<Uri> Urls { get; } = new List<Uri>();
public List<string> Urls { get; } = new List<string>();
public List<int> Ports { get; } = new List<int>();
@@ -76,7 +80,7 @@ namespace WireMock.Owin
var servers = new List<IDisposable>();
foreach (var url in Urls)
{
servers.Add(WebApp.Start(url.ToString(), startup));
servers.Add(WebApp.Start(url, startup));
}
IsStarted = true;

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.2.2</Version>
<Version>1.0.2.3</Version>
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
<TargetFrameworks>net45;net452;net46;netstandard1.3</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>