From 11d4a84bd890f270f4557f936d66c1238b375062 Mon Sep 17 00:00:00 2001 From: David Walter Date: Sat, 28 Jan 2023 18:41:04 +0100 Subject: [PATCH] Fix hasConnection (#470) close #375 --- Packages/Network/Sources/Network/Client.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Packages/Network/Sources/Network/Client.swift b/Packages/Network/Sources/Network/Client.swift index a16b7eba..8883c365 100644 --- a/Packages/Network/Sources/Network/Client.swift +++ b/Packages/Network/Sources/Network/Client.swift @@ -50,7 +50,13 @@ public class Client: ObservableObject, Equatable { public func hasConnection(with url: URL) -> Bool { guard let host = url.host else { return false } - return connections.contains(host) + if let rootHost = host.split(separator: ".", maxSplits: 1).last { + // Sometimes the connection is with the root host instead of a subdomain + // eg. Mastodon runs on mastdon.domain.com but the connection is with domain.com + return connections.contains(host) || connections.contains(String(rootHost)) + } else { + return connections.contains(host) + } } private func makeURL(scheme: String = "https", endpoint: Endpoint, forceVersion: Version? = nil) -> URL {