diff --git a/Sources/WebSocketKit/WebSocket+Connect.swift b/Sources/WebSocketKit/WebSocket+Connect.swift index b5207ee0..4259659c 100644 --- a/Sources/WebSocketKit/WebSocket+Connect.swift +++ b/Sources/WebSocketKit/WebSocket+Connect.swift @@ -20,6 +20,7 @@ extension WebSocket { on eventLoopGroup: EventLoopGroup, onUpgrade: @Sendable @escaping (WebSocket) -> () ) -> EventLoopFuture { + #if canImport(Foundation) let optionalURL: URL? if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) { optionalURL = URL(string: url, encodingInvalidCharacters: false) @@ -37,8 +38,20 @@ extension WebSocket { on: eventLoopGroup, onUpgrade: onUpgrade ) + #else + guard let url = URL(string: url) else { + return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL) + } + return self.connect( + to: url, + headers: headers, + configuration: configuration, + on: eventLoopGroup, + onUpgrade: onUpgrade + ) + #endif } - + /// Establish a WebSocket connection. /// /// - Parameters: @@ -69,7 +82,7 @@ extension WebSocket { onUpgrade: onUpgrade ) } - + /// Establish a WebSocket connection. /// /// - Parameters: @@ -108,7 +121,7 @@ extension WebSocket { onUpgrade: onUpgrade ) } - + /// Establish a WebSocket connection via a proxy server. /// /// - Parameters: @@ -159,8 +172,8 @@ extension WebSocket { onUpgrade: onUpgrade ) } - - + + /// Description /// - Parameters: /// - url: URL for the origin server.