| | | 1 | | using System; |
| | | 2 | | using JetBrains.Annotations; |
| | | 3 | | using WireMock.Models; |
| | | 4 | | #if !USE_ASPNETCORE |
| | | 5 | | using Microsoft.Owin; |
| | | 6 | | #else |
| | | 7 | | using Microsoft.AspNetCore.Http; |
| | | 8 | | #endif |
| | | 9 | | |
| | | 10 | | namespace WireMock.Util |
| | | 11 | | { |
| | | 12 | | internal static class UrlUtils |
| | | 13 | | { |
| | | 14 | | public static UrlDetails Parse([NotNull] Uri uri, PathString pathBase) |
| | 51 | 15 | | { |
| | 51 | 16 | | if (!pathBase.HasValue) |
| | 47 | 17 | | { |
| | 47 | 18 | | return new UrlDetails(uri, uri); |
| | | 19 | | } |
| | | 20 | | |
| | 4 | 21 | | var builder = new UriBuilder(uri); |
| | 4 | 22 | | builder.Path = RemoveFirst(builder.Path, pathBase.Value); |
| | | 23 | | |
| | 4 | 24 | | return new UrlDetails(uri, builder.Uri); |
| | 51 | 25 | | } |
| | | 26 | | |
| | | 27 | | private static string RemoveFirst(string text, string search) |
| | 4 | 28 | | { |
| | 4 | 29 | | int pos = text.IndexOf(search); |
| | 4 | 30 | | if (pos < 0) |
| | 1 | 31 | | { |
| | 1 | 32 | | return text; |
| | | 33 | | } |
| | | 34 | | |
| | 3 | 35 | | return text.Substring(0, pos) + text.Substring(pos + search.Length); |
| | 4 | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |