From 3ac295412905769fed57432d7b89ff7b6be87b42 Mon Sep 17 00:00:00 2001 From: cham-s Date: Mon, 22 Apr 2024 15:38:05 +0200 Subject: [PATCH] Add availability conditional for URL init --- Sources/WebSocketKit/WebSocket+Connect.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/WebSocketKit/WebSocket+Connect.swift b/Sources/WebSocketKit/WebSocket+Connect.swift index 575233d7..b421ed1b 100644 --- a/Sources/WebSocketKit/WebSocket+Connect.swift +++ b/Sources/WebSocketKit/WebSocket+Connect.swift @@ -20,12 +20,19 @@ extension WebSocket { on eventLoopGroup: EventLoopGroup, onUpgrade: @Sendable @escaping (WebSocket) -> () ) -> EventLoopFuture { - guard - url.hasPrefix("ws://") || url.hasPrefix("wss://"), - let url = URL(string: url) - else { + let optionalURL: URL? + if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, visionOS 1.0, *) { + optionalURL = URL( + string: url, + encodingInvalidCharacters: false + ) + } else { + optionalURL = URL(string: url) + } + guard let url = optionalURL else { return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL) } + return self.connect( to: url, headers: headers,