| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus.Primitives |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | |
|
| | 8 | | static class ServiceBusUriHelper |
| | 9 | | { |
| | 10 | | internal static string NormalizeUri(string uri, string scheme, bool stripQueryParameters = true, bool stripPath |
| | 11 | | { |
| 0 | 12 | | var uriBuilder = new UriBuilder(uri) |
| 0 | 13 | | { |
| 0 | 14 | | Scheme = scheme, |
| 0 | 15 | | Port = -1, |
| 0 | 16 | | Fragment = string.Empty, |
| 0 | 17 | | Password = string.Empty, |
| 0 | 18 | | UserName = string.Empty, |
| 0 | 19 | | }; |
| | 20 | |
|
| 0 | 21 | | if (stripPath) |
| | 22 | | { |
| 0 | 23 | | uriBuilder.Path = string.Empty; |
| | 24 | | } |
| | 25 | |
|
| 0 | 26 | | if (stripQueryParameters) |
| | 27 | | { |
| 0 | 28 | | uriBuilder.Query = string.Empty; |
| | 29 | | } |
| | 30 | |
|
| 0 | 31 | | if (ensureTrailingSlash) |
| | 32 | | { |
| 0 | 33 | | if (!uriBuilder.Path.EndsWith("/", StringComparison.Ordinal)) |
| | 34 | | { |
| 0 | 35 | | uriBuilder.Path += "/"; |
| | 36 | | } |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | return uriBuilder.Uri.AbsoluteUri; |
| | 40 | | } |
| | 41 | | } |
| | 42 | | } |