* 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

@@ -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;
}
}
}