Skip to content

Commit 3ac2954

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Sources/WebSocketKit/WebSocket+Connect.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ 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(
26+
string: url,
27+
encodingInvalidCharacters: false
28+
)
29+
} else {
30+
optionalURL = URL(string: url)
31+
}
32+
guard let url = optionalURL else {
2733
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
2834
}
35+
2936
return self.connect(
3037
to: url,
3138
headers: headers,

0 commit comments

Comments
 (0)