mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-22 16:58:06 +01: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
39 lines
913 B
C#
39 lines
913 B
C#
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);
|
|
}
|
|
}
|
|
}
|