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 cb04a37
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions Sources/WebSocketKit/WebSocket+Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,32 @@ extension WebSocket {
on eventLoopGroup: EventLoopGroup,
onUpgrade: @Sendable @escaping (WebSocket) -> ()
) -> EventLoopFuture<Void> {
guard
url.hasPrefix("ws://") || url.hasPrefix("wss://"),
let url = URL(string: url)
else {
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, visionOS 1.0, *) {
guard let url = URL(
string: url,
encodingInvalidCharacters: false
) else {
return eventLoopGroup.any().makeFailedFuture(WebSocketClient.Error.invalidURL)
}
return self.connect(
to: url,
headers: headers,
configuration: configuration,
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
)
}
return self.connect(
to: url,
headers: headers,
configuration: configuration,
on: eventLoopGroup,
onUpgrade: onUpgrade
)
}

/// Establish a WebSocket connection.
Expand Down

0 comments on commit cb04a37

Please sign in to comment.