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
This commit is contained in:
Mark Monteiro
2020-05-10 14:36:11 -04:00
parent 15fd4812f0
commit 43c22a5822
6 changed files with 38 additions and 23 deletions

View File

@@ -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);
return GetLocalApiUrl("127.0.0.1", Uri.UriSchemeHttp, HttpPort);
}
string baseUrl = ServerConfigurationManager.Configuration.BaseUrl;
if (baseUrl.Length != 0)
/// <inheritdoc/>
public Uri GetLocalApiUrl(ReadOnlySpan<char> host, string scheme = null, int? port = null)
{
return new UriBuilder
{
url.Append(baseUrl);
}
return url.ToString();
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)