mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 08:48:28 +02:00
* Update examples (#158) * IIS debug * PathBase logic * 1.0.4.5-preview-01 * Fix project and readme * Fix issues * fix picture alignment * Add IIS publish examples * 1.0.4.5
This commit is contained in:
38
src/WireMock.Net/Util/UrlUtils.cs
Normal file
38
src/WireMock.Net/Util/UrlUtils.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Models;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
internal static class UrlUtils
|
||||
{
|
||||
public static UrlDetails Parse([NotNull] Uri uri, PathString pathBase)
|
||||
{
|
||||
if (!pathBase.HasValue)
|
||||
{
|
||||
return new UrlDetails(uri, uri);
|
||||
}
|
||||
|
||||
var builder = new UriBuilder(uri);
|
||||
builder.Path = RemoveFirst(builder.Path, pathBase.Value);
|
||||
|
||||
return new UrlDetails(uri, builder.Uri);
|
||||
}
|
||||
|
||||
private static string RemoveFirst(string text, string search)
|
||||
{
|
||||
int pos = text.IndexOf(search);
|
||||
if (pos < 0)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
return text.Substring(0, pos) + text.Substring(pos + search.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user