-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle URL changes in latest Apple Platforms #148
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #148 +/- ##
==========================================
- Coverage 82.85% 82.55% -0.30%
==========================================
Files 6 6
Lines 659 642 -17
==========================================
- Hits 546 530 -16
+ Misses 113 112 -1
|
@cham-s just taking a look at this to see why CI is failing - it's failing to build on latest macOS for me because |
@0xTim websocket-kit/Tests/WebSocketKitTests/WebSocketKitTests.swift Lines 481 to 487 in 4232d34
websocket-kit/Tests/WebSocketKitTests/AsyncWebSocketKitTests.swift Lines 49 to 60 in 4232d34
The tests expect "%w" to fail because it's not a valid URI. websocket-kit/Sources/WebSocketKit/WebSocket+Connect.swift Lines 16 to 33 in 4232d34
I verified it with a repl session:
As a fix I allowed myself to try to strengthen the public static func connect(
to url: String,
headers: HTTPHeaders = [:],
configuration: WebSocketClient.Configuration = .init(),
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)
}
return self.connect(
to: url,
headers: headers,
configuration: configuration,
on: eventLoopGroup,
onUpgrade: onUpgrade
)
} I don't know if this is the best solution but it makes sure the caller first, inputs a string with a correct WebSocket scheme then let URL(string: String) perform additional checks. |
Ok this is a change in behaviour in Swift - see https://developer.apple.com/documentation/foundation/url/3126806-init for an explanation So I think the answer to this is use the new API if available https://developer.apple.com/documentation/foundation/url/4191020-init otherwise default to the old one. Another option if find a URL that still fails and update the test |
@0xTim thanks for the links, I wasn't aware of this change. The code has been updated accordingly. |
Original description: This is not much but after building the package a couple of warnings and errors appeared the following changes made them disappear.
// Before
ws.onPong {
$0.close(promise: closePromise)
promise.succeed()
}
// After
ws.onPong { webSocket, _ in
webSocket.close(promise: closePromise)
promise.succeed()
} Update SSLTestHelpers, remove deprecation warnings |
@cham-s I think we can remove the visionOS check - I don't mind the change of behaviour on that platform! |
Ok, done |
@0xTim tests are passing except for In any case it says if #available(iOS 17.0, macOS 14.3, tvOS 17.0, watchOS 10.0, *) {
optionalURL = URL(string: url, encodingInvalidCharacters: false)
} but doesn't recognise the API. |
|
I withdraw this comment, it looks like I was confused as to what was actually happening here. Apologies for the noise! |
@gwynne #148 (comment) thanks for the info. |
The latest Apple platforms automatically escape invalid URL characters - https://developer.apple.com/documentation/foundation/url/3126806-init
This aligns the behaviour across platform versions and Linux. Also updates a number of warnings in the tests