mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 11:21:51 +01:00
Listen on http://*:9090 (#39)
* Support for http://*:9090 urls * Update version to 1.0.2.3
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"WireMock.Net.StandAlone.NETCoreApp": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "--Urls http://*:9090"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace WireMock.Http
|
namespace WireMock.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ports.
|
/// Utility class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class PortUtil
|
public static class PortUtil
|
||||||
{
|
{
|
||||||
|
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)?/", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The find free TCP port.
|
/// The find free TCP port.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -30,5 +33,24 @@ namespace WireMock.Http
|
|||||||
tcpListener?.Stop();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#if NETSTANDARD
|
#if NETSTANDARD
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,6 +7,7 @@ using Microsoft.AspNetCore.Builder;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using WireMock.Http;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
namespace WireMock.Owin
|
namespace WireMock.Owin
|
||||||
@@ -20,7 +20,7 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
public bool IsStarted { get; private set; }
|
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>();
|
public List<int> Ports { get; } = new List<int>();
|
||||||
|
|
||||||
@@ -31,9 +31,12 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
foreach (string uriPrefix in uriPrefixes)
|
foreach (string uriPrefix in uriPrefixes)
|
||||||
{
|
{
|
||||||
var uri = new Uri(uriPrefix);
|
Urls.Add(uriPrefix);
|
||||||
Urls.Add(uri);
|
|
||||||
Ports.Add(uri.Port);
|
int port;
|
||||||
|
string host;
|
||||||
|
PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
|
||||||
|
Ports.Add(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
_options = options;
|
_options = options;
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ namespace WireMock.Owin
|
|||||||
bool IsStarted { get; }
|
bool IsStarted { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the url.
|
/// Gets the urls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// The urls.
|
/// The urls.
|
||||||
/// </value>
|
/// </value>
|
||||||
List<Uri> Urls { get; }
|
List<string> Urls { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the ports.
|
/// Gets the ports.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using JetBrains.Annotations;
|
|||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
using Owin;
|
using Owin;
|
||||||
using Microsoft.Owin.Hosting;
|
using Microsoft.Owin.Hosting;
|
||||||
|
using WireMock.Http;
|
||||||
|
|
||||||
namespace WireMock.Owin
|
namespace WireMock.Owin
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,7 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
private readonly WireMockMiddlewareOptions _options;
|
private readonly WireMockMiddlewareOptions _options;
|
||||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||||
private System.Threading.Thread _internalThread;
|
private Thread _internalThread;
|
||||||
|
|
||||||
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||||
{
|
{
|
||||||
@@ -23,9 +24,12 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
foreach (string uriPrefix in uriPrefixes)
|
foreach (string uriPrefix in uriPrefixes)
|
||||||
{
|
{
|
||||||
var uri = new Uri(uriPrefix);
|
Urls.Add(uriPrefix);
|
||||||
Urls.Add(uri);
|
|
||||||
Ports.Add(uri.Port);
|
int port;
|
||||||
|
string host;
|
||||||
|
PortUtil.TryExtractProtocolAndPort(uriPrefix, out host, out port);
|
||||||
|
Ports.Add(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
_options = options;
|
_options = options;
|
||||||
@@ -33,7 +37,7 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
public bool IsStarted { get; private set; }
|
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>();
|
public List<int> Ports { get; } = new List<int>();
|
||||||
|
|
||||||
@@ -76,7 +80,7 @@ namespace WireMock.Owin
|
|||||||
var servers = new List<IDisposable>();
|
var servers = new List<IDisposable>();
|
||||||
foreach (var url in Urls)
|
foreach (var url in Urls)
|
||||||
{
|
{
|
||||||
servers.Add(WebApp.Start(url.ToString(), startup));
|
servers.Add(WebApp.Start(url, startup));
|
||||||
}
|
}
|
||||||
|
|
||||||
IsStarted = true;
|
IsStarted = true;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||||
<Version>1.0.2.2</Version>
|
<Version>1.0.2.3</Version>
|
||||||
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
|
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net45;net452;net46;netstandard1.3</TargetFrameworks>
|
<TargetFrameworks>net45;net452;net46;netstandard1.3</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
|||||||
Reference in New Issue
Block a user