mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-17 23:03:46 +01:00
* net451 * tests : net462 * fixed tests * fix tests * readme * Code review * LocalFileSystemHandlerTests * refactor
39 lines
916 B
C#
39 lines
916 B
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using WireMock.Models;
|
|
#if !USE_ASPNETCORE
|
|
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);
|
|
}
|
|
}
|
|
}
|