From a9b3fa8b0b0c6b882e7faa08a870cb29751c7e42 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Sat, 16 Dec 2023 16:36:39 -0600 Subject: [PATCH] Add CancellationToken support to ShopDomainUtility.IsValidShopDomainAsync --- ShopifySharp/Utilities/ShopifyDomainUtility.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ShopifySharp/Utilities/ShopifyDomainUtility.cs b/ShopifySharp/Utilities/ShopifyDomainUtility.cs index 2fbfe6e6c..eb67de951 100644 --- a/ShopifySharp/Utilities/ShopifyDomainUtility.cs +++ b/ShopifySharp/Utilities/ShopifyDomainUtility.cs @@ -22,8 +22,9 @@ public interface IShopifyDomainUtility ///

**Warning**: this method of validation is not officially supported by Shopify and could break at any time.

/// /// The shop domain to check. This should be a *.myshopify.com domain. - /// A boolean indicating whether the URL is valid. - Task IsValidShopDomainAsync(string shopDomain); + /// A cancellation token which can cancel the request. + /// Returns true if the shop domain is a Shopify store. + Task IsValidShopDomainAsync(string shopDomain, CancellationToken cancellationToken = default); } public class ShopifyDomainUtility : IShopifyDomainUtility @@ -49,7 +50,7 @@ public Uri BuildShopDomainUri(string shopDomain) } /// - public async Task IsValidShopDomainAsync(string shopDomain) + public async Task IsValidShopDomainAsync(string shopDomain, CancellationToken cancellationToken = default) { var requestUri = BuildShopDomainUri(shopDomain); var client = _httpClientFactory.CreateClient(); @@ -58,8 +59,10 @@ public async Task IsValidShopDomainAsync(string shopDomain) try { - var response = await client.SendAsync(msg); - return response.Headers.Any(h => h.Key.Equals("X-ShopId", StringComparison.OrdinalIgnoreCase)); + var response = await client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + var hasShopIdHeader = response.Headers.Any(h => h.Key.Equals("X-ShopId", StringComparison.OrdinalIgnoreCase)); + + return hasShopIdHeader; } catch (HttpRequestException) {