Skip to content

Commit

Permalink
Add availability conditional for URL init
Browse files Browse the repository at this point in the history
  • Loading branch information
cham-s committed Apr 22, 2024
1 parent 24ea66e commit 1af749d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ extension WebSocket {
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
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,
Expand Down

0 comments on commit 1af749d

Please sign in to comment.