Files
WireMock.Net-wiremock/src/WireMock.Net/Util/UrlUtils.cs
Stef Heyenrath b57d118c3d Support Microsoft.AspNetCore for net 4.6.1 and up (#185)
* net451

* tests : net462

* fixed tests

* fix tests

* readme

* Code review

* LocalFileSystemHandlerTests

* refactor
2018-08-17 18:52:29 +02:00

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