From a564df42d6a3d205e9bd63012097ab93a206cdad Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 10 Aug 2018 11:21:52 -0400 Subject: [PATCH] try base domain if others fail --- src/Icons/Services/IconFetchingService.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Icons/Services/IconFetchingService.cs b/src/Icons/Services/IconFetchingService.cs index bb5bf942c..b2accce26 100644 --- a/src/Icons/Services/IconFetchingService.cs +++ b/src/Icons/Services/IconFetchingService.cs @@ -64,12 +64,23 @@ namespace Bit.Icons.Services uri = parsedHttpUri; response = await GetAndFollowAsync(uri, 2); - if((response == null || !response.IsSuccessStatusCode) && - Uri.TryCreate($"https://www.{parsedHttpsUri.Host}", UriKind.Absolute, out var parsedWwwUri)) + if(response == null || !response.IsSuccessStatusCode) { - Cleanup(response); - uri = parsedWwwUri; - response = await GetAndFollowAsync(uri, 2); + var dotCount = domain.Count(c => c == '.'); + if(dotCount > 1 && DomainName.TryParseBaseDomain(domain, out var baseDomain) && + Uri.TryCreate($"https://{baseDomain}", UriKind.Absolute, out var parsedBaseUri)) + { + Cleanup(response); + uri = parsedBaseUri; + response = await GetAndFollowAsync(uri, 2); + } + else if(dotCount < 2 && + Uri.TryCreate($"https://www.{parsedHttpsUri.Host}", UriKind.Absolute, out var parsedWwwUri)) + { + Cleanup(response); + uri = parsedWwwUri; + response = await GetAndFollowAsync(uri, 2); + } } }