diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2018-12-29 19:39:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-29 19:39:05 -0500 |
| commit | 64a1a7560ee09b1568e65def65fe51bf84357726 (patch) | |
| tree | ebf3a5f911228a57ecefb01dfef6bf45e19fd153 /Emby.Server.Implementations | |
| parent | ff88936f8b1c919ecd900d4355cc0977833fbef2 (diff) | |
| parent | aac1007bdc0167c83ef150d199c27cfaed467e44 (diff) | |
Merge branch 'dev' into fix-issue-320
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 35 | ||||
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 13 |
2 files changed, 38 insertions, 10 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f8dd65bbc..ad15b015d 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1962,6 +1962,7 @@ namespace Emby.Server.Implementations public async Task<SystemInfo> GetSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); + var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); return new SystemInfo { @@ -1984,8 +1985,7 @@ namespace Emby.Server.Implementations CanSelfRestart = CanSelfRestart, CanSelfUpdate = CanSelfUpdate, CanLaunchWebBrowser = CanLaunchWebBrowser, - // TODO - remove WanAddress - WanAddress = "0.0.0.0", + WanAddress = wanAddress, HasUpdateAvailable = HasUpdateAvailable, SupportsAutoRunAtStartup = SupportsAutoRunAtStartup, TranscodingTempPath = ApplicationPaths.TranscodingTempPath, @@ -2012,14 +2012,13 @@ namespace Emby.Server.Implementations public async Task<PublicSystemInfo> GetPublicSystemInfo(CancellationToken cancellationToken) { var localAddress = await GetLocalApiUrl(cancellationToken).ConfigureAwait(false); - + var wanAddress = await GetWanApiUrl(cancellationToken).ConfigureAwait(false); return new PublicSystemInfo { Version = ApplicationVersion.ToString(), Id = SystemId, OperatingSystem = EnvironmentInfo.OperatingSystem.ToString(), - // TODO - remove WanAddress - WanAddress = "0.0.0.0", + WanAddress = wanAddress, ServerName = FriendlyName, LocalAddress = localAddress }; @@ -2060,6 +2059,32 @@ namespace Emby.Server.Implementations return null; } + public async Task<string> GetWanApiUrl(CancellationToken cancellationToken) + { + var url = "http://ipv4.icanhazip.com"; + try + { + using (var response = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + LogErrorResponseBody = false, + LogErrors = false, + LogRequest = false, + TimeoutMs = 10000, + BufferContent = false, + CancellationToken = cancellationToken + })) + { + return GetLocalApiUrl(response.ReadToEnd().Trim()); + } + } + catch(Exception ex) + { + Logger.ErrorException("Error getting WAN Ip address information", ex); + } + return null; + } + public string GetLocalApiUrl(IpAddressInfo ipAddress) { if (ipAddress.AddressFamily == IpAddressFamily.InterNetworkV6) diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index df493b4c3..a0a471cb2 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -112,12 +112,15 @@ namespace Emby.Server.Implementations.HttpServer /// </summary> private IHasHeaders GetHttpResult(IRequest requestContext, byte[] content, string contentType, bool addCachePrevention, IDictionary<string, string> responseHeaders = null) { - IHasHeaders result; - - var compressionType = requestContext == null ? null : GetCompressionType(requestContext, content, contentType); + string compressionType = null; + bool isHeadRequest = false; - var isHeadRequest = string.Equals(requestContext.Verb, "head", StringComparison.OrdinalIgnoreCase); + if (requestContext != null) { + compressionType = GetCompressionType(requestContext, content, contentType); + isHeadRequest = string.Equals(requestContext.Verb, "head", StringComparison.OrdinalIgnoreCase); + } + IHasHeaders result; if (string.IsNullOrEmpty(compressionType)) { var contentLength = content.Length; @@ -791,4 +794,4 @@ namespace Emby.Server.Implementations.HttpServer { byte[] Compress(byte[] content); } -}
\ No newline at end of file +} |
