Skip to content

Commit 1af749d

Browse files
committed
Add availability conditional for URL init
1 parent 24ea66e commit 1af749d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/WebSocketKit/WebSocket+Connect.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ extension WebSocket {
2020
on eventLoopGroup: EventLoopGroup,
2121
onUpgrade: @Sendable @escaping (WebSocket) -> ()
2222
) -> EventLoopFuture<Void> {
23-
guard
24-
url.hasPrefix("ws://") || url.hasPrefix("wss://"),
25-
let url = URL(string: url)
26-
else {
23+
let optionalURL: URL?
24+
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, visionOS 1.0, *) {
25+
optionalURL = URL(string: url, encodingInvalidCharacters: false)
26+
} else {
27+
optionalURL = URL(string: url)
28+
}
29+
guard let url = optionalURL else {
2730
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
2831
}
32+
2933
return self.connect(
3034
to: url,
3135
headers: headers,

0 commit comments

Comments
 (0)