diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-05-10 14:36:11 -0400 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-05-10 14:36:11 -0400 |
| commit | 43c22a58229892836df645031fb570f37994e19e (patch) | |
| tree | 78223ac23c1091245df8ac36db9ad486277ec20a /Emby.Server.Implementations/ApplicationHost.cs | |
| parent | 15fd4812f09282e9b81f53845ce462f42ff1b5e9 (diff) | |
Add GetLoopbackHttpApiUrl() helper method to replace forceHttps functionality
Also refactor to use return a Uri instead of a string and use UriBuilder under the hood
Diffstat (limited to 'Emby.Server.Implementations/ApplicationHost.cs')
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8f20a4921f..2201c3cfc2 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1229,28 +1229,28 @@ namespace Emby.Server.Implementations str.CopyTo(span.Slice(1)); span[^1] = ']'; - return GetLocalApiUrl(span); + return GetLocalApiUrl(span).ToString(); } - return GetLocalApiUrl(ipAddress.ToString()); + return GetLocalApiUrl(ipAddress.ToString()).ToString(); } /// <inheritdoc/> - public string GetLocalApiUrl(ReadOnlySpan<char> host) + public Uri GetLoopbackHttpApiUrl() { - var url = new StringBuilder(64); - url.Append(ListenWithHttps ? "https://" : "http://") - .Append(host) - .Append(':') - .Append(ListenWithHttps ? HttpsPort : HttpPort); - - string baseUrl = ServerConfigurationManager.Configuration.BaseUrl; - if (baseUrl.Length != 0) - { - url.Append(baseUrl); - } + return GetLocalApiUrl("127.0.0.1", Uri.UriSchemeHttp, HttpPort); + } - return url.ToString(); + /// <inheritdoc/> + public Uri GetLocalApiUrl(ReadOnlySpan<char> host, string scheme = null, int? port = null) + { + return new UriBuilder + { + Scheme = scheme ?? (ListenWithHttps ? Uri.UriSchemeHttps : Uri.UriSchemeHttp), + Host = host.ToString(), + Port = port ?? (ListenWithHttps ? HttpsPort : HttpPort), + Path = ServerConfigurationManager.Configuration.BaseUrl + }.Uri; } public Task<List<IPAddress>> GetLocalIpAddresses(CancellationToken cancellationToken) |
