aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Net
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2021-08-04 18:43:26 +0200
committerBond_009 <bond.009@outlook.com>2021-08-04 18:43:26 +0200
commit442dc10aaccf153873fd711dc80ee55052fc2063 (patch)
tree87ab8a8e3882c95c89234a111c71bbbdc15186cd /MediaBrowser.Common/Net
parent2521a13d7d8df3bfa5291386ba4389469f02ade8 (diff)
ApiServiceCollectionExtensions.AddProxyAddresses: Add more tests
Diffstat (limited to 'MediaBrowser.Common/Net')
-rw-r--r--MediaBrowser.Common/Net/IPHost.cs42
1 files changed, 21 insertions, 21 deletions
diff --git a/MediaBrowser.Common/Net/IPHost.cs b/MediaBrowser.Common/Net/IPHost.cs
index d78d7def2..bdadcbf95 100644
--- a/MediaBrowser.Common/Net/IPHost.cs
+++ b/MediaBrowser.Common/Net/IPHost.cs
@@ -4,7 +4,6 @@ using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
-using System.Threading.Tasks;
namespace MediaBrowser.Common.Net
{
@@ -400,7 +399,7 @@ namespace MediaBrowser.Common.Net
if ((_addresses.Length == 0 && !Resolved) || (DateTime.UtcNow > _lastResolved.Value.AddMinutes(Timeout)))
{
_lastResolved = DateTime.UtcNow;
- ResolveHostInternal().GetAwaiter().GetResult();
+ ResolveHostInternal();
Resolved = true;
}
@@ -410,30 +409,31 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// Task that looks up a Host name and returns its IP addresses.
/// </summary>
- /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
- private async Task ResolveHostInternal()
+ private void ResolveHostInternal()
{
- if (!string.IsNullOrEmpty(HostName))
+ var hostName = HostName;
+ if (string.IsNullOrEmpty(hostName))
{
- // Resolves the host name - so save a DNS lookup.
- if (string.Equals(HostName, "localhost", StringComparison.OrdinalIgnoreCase))
+ return;
+ }
+
+ // Resolves the host name - so save a DNS lookup.
+ if (string.Equals(hostName, "localhost", StringComparison.OrdinalIgnoreCase))
+ {
+ _addresses = new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback };
+ return;
+ }
+
+ if (Uri.CheckHostName(hostName) == UriHostNameType.Dns)
+ {
+ try
{
- _addresses = new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback };
- return;
+ _addresses = Dns.GetHostAddresses(hostName);
}
-
- if (Uri.CheckHostName(HostName).Equals(UriHostNameType.Dns))
+ catch (SocketException ex)
{
- try
- {
- IPHostEntry ip = await Dns.GetHostEntryAsync(HostName).ConfigureAwait(false);
- _addresses = ip.AddressList;
- }
- catch (SocketException ex)
- {
- // Log and then ignore socket errors, as the result value will just be an empty array.
- Debug.WriteLine("GetHostEntryAsync failed with {Message}.", ex.Message);
- }
+ // Log and then ignore socket errors, as the result value will just be an empty array.
+ Debug.WriteLine("GetHostEntryAsync failed with {Message}.", ex.Message);
}
}
}